2021-05-27 07:39 AM
Hello,
I am trying to recognize a number sent to USART:
If I send '123' over USART to MCU then MCU receives only '3' (the last character). Variable recv has uint8_t (unsigned integer) type. How could I receive the complete number ('123')?
I am using STM32L0 MCU and STM32CubeIDE environment.
Thank you.
2021-05-27 08:35 AM
> if (recv == '123')
> If I send '123' over USART to MCU then MCU receives only '3' (the last character).
From the C standard:
The value of an integer character constant containing more than one character (e.g.,
'ab'), or containing a character or escape sequence that does not map to a single-byte
execution character, is implementation-defined.
In other words, it depends on the compiler, how is '123' interpreted; however, the result is a single number, not any magical way to compare multiple possible values.
You may want to look up the strchr() standard library function.
JW
2021-05-27 08:53 AM
You'd need to accumulate a byte at a time into a buffer, and then parse when you have enough data to work with.
A single byte could hold the value 123, ie (recv == 123)
Or in ASCII it would be a string containing three decimal digits, ie "123"