cancel
Showing results for 
Search instead for 
Did you mean: 

Receiving wrong Data in UART in Nucleo Board.

SayanSeth
Associate II

Hi, I was testing UART communication using F446RE Nucleo Board. I was sending data to COM port by a python program running in PC and trying the receive to same data.

ser.write(serial.to_bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]))
print(ser.read(15))
memset(rx_buffer,0, 15);
		HAL_UART_Receive(&huart2,rx_buffer, 15, HAL_MAX_DELAY);
		HAL_UART_Transmit(&huart2,rx_buffer, 15, HAL_MAX_DELAY);

I'm getting below data.

b'\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'

I tried same code in two different board. both are giving same result.

1 ACCEPTED SOLUTION

Accepted Solutions

Because you send these bytes, and the STM32 sends them back.

The python interpreter then decided to display the sequence of bytes using some escape sequences. The python documentation on data types and the print function might document the exact reason why 9 is turned into '\t', 10 into '\n', and 11 into '\x0b' etc.

View solution in original post

4 REPLIES 4
berendi
Principal

And what's the problem with that? The STM32 sends the same sequence back, you might want to convert the byte sequence to an array of bytes on the python side.

Why the below parts are coming?

\t\n\x0b\x0c\r\

Because you send these bytes, and the STM32 sends them back.

The python interpreter then decided to display the sequence of bytes using some escape sequences. The python documentation on data types and the print function might document the exact reason why 9 is turned into '\t', 10 into '\n', and 11 into '\x0b' etc.

Oh, thank you very much. I'm checking the documentation.