2020-02-10 02:45 AM
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.
Solved! Go to Solution.
2020-02-10 03:12 AM
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.
2020-02-10 02:59 AM
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.
2020-02-10 03:02 AM
Why the below parts are coming?
\t\n\x0b\x0c\r\
2020-02-10 03:12 AM
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.
2020-02-10 03:18 AM
Oh, thank you very much. I'm checking the documentation.