cancel
Showing results for 
Search instead for 
Did you mean: 

USART Receive multiple characters

Indois
Associate II

Hello,

I am trying to recognize a number sent to USART:

0693W00000AQ4qIQAT.pngIf 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.

2 REPLIES 2

> 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

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"

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..