Skip to main content
xpp07
Associate III
November 11, 2018
Question

Reading 16 bit word with SPI

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?

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    November 11, 2018

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