|
From: | Andreas Höschler |
Subject: | Re: [avr-gcc-list] Converting string to uint32_t |
Date: | Tue, 14 Oct 2014 19:30:59 +0200 |
Hi all, thanks for your responses that helped a lot to solve the problem: The truncation is probably happening here--- utoa() takes an unsigned 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; uint32_t ret = (uint32_t)strtoul(char_buffer, NULL, 0); return ret; } } } return -1; } void putLong_in_serial_trans_buffer(uint32_t value) { char char_buffer[10]; ltoa(value, char_buffer, 10); int i; for (i = 0 ; i < 10 ; i++) { char current = char_buffer[i]; if (current != 0) TxByte (current); else break; } } Thanks, Andreas |
[Prev in Thread] | Current Thread | [Next in Thread] |