cancel
Showing results for 
Search instead for 
Did you mean: 

Reading 16 bit word with SPI

xpp07
Senior

I have declared the following variable:

uint16_t SPIRx;

If I use this line to read SPI data, the compiler doesn't throw warnings:

HAL_SPI_Receive(&hspi1, (uint8_t *)&SPIRx, 2, 500);

But if I say:

HAL_SPI_Receive(&hspi1, (uint16_t *)&SPIRx, 1, 500);

It throws a warning because the pointer should be 8 bit.

What is the right way to use the SPI Receive module to read a 16 bit word?

1 REPLY 1

The pointer needs to be cast as 8-bit either way, but the count depends on the width you have told the SPI peripheral to use.​

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