avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Converting string to uint32_t


From: Andreas Höschler
Subject: [avr-gcc-list] Converting string to uint32_t
Date: Mon, 13 Oct 2014 23:57:57 +0200

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]