Hi all,

doing my first cautious steps in C on an Arduino I try to convert a string read 
over the serial interface to a uint32_t.

uint32_t getLong_from_serial_rec_buffer()
  {
   char char_buffer[10];
   int i;
   for (i = 0 ; i < 10 ; i++)
     {
      if (bytes_in_serial_rec_buffer() > 0)
        {
         char current = buffer[buffer_tail];
         if (current >= '0' && current <= '9')
           {
            get_from_serial_rec_buffer(); // we already know the byte :-)
            char_buffer[i] = current;
           }
         else // is a comma or NULL or whatever other character
           {
            char_buffer[i] = 0;
            
            putString_in_serial_trans_buffer(char_buffer);
            
            return (uint32_t)atol(char_buffer);
           }
        }
     } 
   return -1;
  }

void putLong_in_serial_trans_buffer(uint32_t value)
{
   char char_buffer[10];
   utoa(value, char_buffer, 10); 
   int i;
   for (i = 0 ; i < 10 ; i++)
    {
      char current = char_buffer[i];
      if (current != 0) TxByte (current);
      else break;
    }
}

This does not work. The thing receives 500000 as a string but atol seems to be 
good for 16bit values only!? The value returned by 
getLong_from_serial_rec_buffer is at least always smaller than 65536. What am I 
missing? Where would I find the correct function that returns a 32bit value?

Thanks a lot,

 Andreas


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to