Hi there,
I have a project on the E70 where I am getting input from an external display over RS232 (USART) as a comma separated string, and would like to parse the values in the string to variables in my program. I am using the DMA to transfer the incoming data to a variable "usart_receive_buffer". The code below is run in a loop every 20 ms.
What I am finding is very intermittently (less than 0.1% of the time) but irregularly, atoff() is giving incorrect conversion values. With reference to the snippet below, a breakpoint at error = 1 is hit, even though the first element is set to 0.60. The error is always the same value though, "0.609000027". I find this odd, because "dest_buf1" is always "0.60" (or, {0x30,0x2e,0x36,0x30}) so I don't know where the third decimal place is coming from.
I guess there is something wrong elsewhere in my project, because if I put this code into its own project and run it in the while loop, the break point is never hit.
I tried eliminating the possibility that the DMA was changing the string while all this was going on by just setting the string to the same value every loop, but that did not change things.
Does anyone have any ideas how I can diagnose this problem?
char dest_buf1[4]; char dest_buf2[4]; float float_buf1, float_buf2; strcpy(usart_receive_data, usart_receive_buffer, 16); // First attempt strcpy(usart_receive_data, "0.60,1.00,1.00\0", 16); // Removed usart_receive_buffer reference to test if (1) { strncpy(dest_buf1, &usart_receive_data[0], 4); float_buf1 = atoff(dest_buf1); if ((float_buf1 > 0.0) && (float_buf1 < 1.1)) rcv1 = (float)float_buf1; // strncpy(dest_buf2, &usart_receive_data[5], 4); float_buf2 = atoff(dest_buf2); if ((float_buf2 > 0.9) && (float_buf2 < 1.1)) rcv2 = (float)float_buf2; } if (rcv1 > 0.6001) { volatile int error = 1; // BREAK POINT HERE. }