cancel
Showing results for 
Search instead for 
Did you mean: 

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

clf88
Associate
	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?

2 REPLIES 2
hpipon957
Associate III

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

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
Up vote any posts that you find helpful, it shows what's working..