Showing results for 
Search instead for 
Did you mean: 

How to read multiple bytes in SPI with HAL

Associate II

Hi everybody,

I've been trying for a while to read multiple bytes from an LIS3MDL accelerometer. I know how to read and write registers but one at a time. I can't figure it out the multiple part...

So, if I want to read from reg 0x27 to 0x2D, I understand that I need to set bit0 to 1 (for read operation) and MS bit to 1 (for multiple read). Then :

TxMagOut[0] = 0x27|0xC0;


RxMagOut[8] = {0}; // initialisation

I use transmiReceive with TxMagOut. I said that my data is 8 bytes so it know when to stop reading (at 0x2D)

HAL_SPI_TransmitReceive(&hspi3,TxMagOut ,RxMagOut , 8, 100);

I should get my data in RxMagOut from [1] to [8]. Right? At least this is my best idea.

Am I doing something wrong? Do someone see an error there?

If there is a simple example with HAL of multiple byte read that you know of ? I would be gratefull.

Thanks! 🙂


AFAIK HAL_SPI_TransmitReceive(&hspi3,TxMagOut ,RxMagOut , 8, 100);

"8" here is number of tx bytes, not the rx bytes as you assumed.

Associate II

Hi @JMart.5, did you end up solving the issue? I have the same problem too.