Facing issues in parsing string received via UART

Showing results for 
Show  only  | Search instead for 
Did you mean: 

Facing issues in parsing string received via UART

Contributor I

We're trying to parse a string we send to the NXP via UART using USB Serial. We basically index the string according to the position of the values we're sending and are trying to recreate a similar string to transmit back after multiplying the extracted values by 1000. Upon testing that model, we're getting correct delimiters, but the populated values are just 5's for the first 2 variables and its null for the 3rd value.

Sample string sent to the nxp is "045.20v345.33d234.77e"
and we're expecting "45200v34522d23477e"
but we're getting back "55555v55555d*****e"

where * is the null character

I've attached the simulink model for reference.

Also, if you could suggest, what would be the best way to do this is? How to take in a string, convert the string into floats to do mathematical computations, and output a string with the computed values and delimiters?


0 Kudos
1 Reply

Contributor I

This project can be implemented in the following manner:

1) Declare a structure with the elements whose values will be received via UART.

2) The UART Rx interrupt must be used to get the ASCII characters. There should be two arrays, one to store the element name like "rate", "gain" etc and another to store the corresponding numerical values in ASCII such as "10000", "4", etc

3) If the ASCII character received is not a numerical number (between 0x30 and 0x39), then store it in the NAME array. If the received ASCII character represents a number, that is, between 0x30 and 0x39, then store it in the NUMBER array.

4) Once a pair of NAME and NUMBER array is received, then the number received is mapped to the element of the structure to which it belongs. For this two operations is to be done in the main. The NAME array should be checked if it is equal to "rate" or "gain". When one of them matches, the corresponding number should be assigned to the element of the structure. The received numerals in ASCII format should be converted to a number. Example, "10000" will be stored as {0x31, 0x30, 0x30, 0x30, 0x30}. A function should be written to convert it to hexadecimal format. This number should be assigned to the element of the structure, like example.rate = 10000, example.gain = 4.



0 Kudos