Skip to main content
clf88
Associate
Jan 28, 2019 9:56 AM UTC
Question

STM32L073RZ: HAL_UART_Receive inverse order of data when printing on terminal.

	HAL_UART_Receive(&huart2, (uint8_t*)msgToTransmit, MESSAGE_SIZE, HAL_MAX_DELAY);
 
	int index = 0;
	for (index = 0; index < MESSAGE_SIZE; index++) {
		PRINTF("\n\rmsg to transmit is hex: %x", msgToTransmit[index]);
		PRINTF("\n\rmsg to transmit is char: %c", msgToTransmit[index]);
 
	}

I am developing an application to send data using LoRa. I use an STM32 L073RZ (with LoRa shield) connected to a Raspberry Pi via USB. Everything works fine: there is a Python script that every 10 minutes sends data to the STM32 board, and then the board sends the LoRa message.

I would like now to "analyze" the message before sending. I tried to print on terminal the message that I send and:

if I send: abcdefgh

the result of PRINTF() with hex is:

index = 0 --> 64636261

index = 1 --> 68676665

the result of PRINTF() with char is:

index = 0 --> a

index = 1 --> e

Any suggestion/idea?

This topic has been closed for replies.

2 replies

hpipon957
Associate III
Jan 28, 2019 11:25 AM UTC

Hi

Print the data as bytes and not unsigned words and you will have no problems.

Don't forget that the processor is little-endian and so the first byte appears at the 3th byte position in the word when displayed as a long word (big-endian processors would display it in the first byte location in the long word).

https://en.wikipedia.org/wiki/Endianness

https://www.youtube.com/watch?v=NcaiHcBvDR4

Regards

Mark

Tesla DeLorean
Guru
Jan 28, 2019 1:04 PM UTC

Start by looking at the definition of the array msgToTransmit, you don't show it but assuming it is an array of 32-bit words.

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