2018-09-19 07:07 PM
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
2018-09-19 08:44 PM
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.
2018-09-19 08:53 PM
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?
2018-09-19 09:04 PM
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.
2018-09-19 09:16 PM
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.