cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a 16-bit word via SPI

xpp07
Senior

In order to read a 16-bit word from a current sensor, is it correct to say:

HAL_SPI_Receive(&hspi1, &SPIRx[0], 1, 1); //?

SPIRx is declared as uint16_t SPIRx[1];

I told CubeMx that the data size for SPI1 is 16 bits

4 REPLIES 4

Probably,

Try looking at the source for HAL_SPI_Receive() function, usually specific comments about parameters/usage.

Seem to recall the length parameter being units of transfer size, so 1 for a single word.

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

I'm confused because the definition says:

HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout),

The second parameter uint8_t *pData, but I have the data as 16 bits. Does it affect?

Isn't it the same routine whether you have the SPI in 8 or 16-bit mode?

I think (void *) would have been better for the general case, but the pointer can be recast.

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

If I do as above, it throws this warning:

passing argument 2 of 'HAL_SPI_Receive' from incompatible pointer type [-Wincompatible-pointer-types]

So, the pointer has to be 8 bits. Seems like I got my wires crossed.