cancel
Showing results for 
Search instead for 
Did you mean: 

How to continuousely loop read few register on SPI slave device, using DMA, when dummy bytes used to generate clock must be specified ( slave register adress) ?

baptor
Associate III

Master is a STM32H757, slave is a LSM6DSO ( accelero + gyro ).

I have a SPI link inbetween.

The "int2" pin on the LSM6 rise up when data are readable in registers.

This pin is connected on EXTI2 on STM32.

Register read is auto incremental on LSM6.

I need to read 12 output registers on LSM6 when int2 pin rise up.

I use BDMA to send over SPI 13 bytes ( register start adress + 12 dummy ). This is triggered with EXTI2, and work well.

So the BDMA for TX is sending what the LSM6 requieres.

On the other side, I have a BDMA channel on SPI rx that transfers to READ BUFFER what the spi miso is reading.

If I use HAL_SPI_TransmitReceive(), with a lenght of 13, the system is looping perfectly, On MOSI I have 13 bytes( register adress + dummys ), and on MISO, I read 13 bytes ( dummys + registers data ), but each (13 bytes ) reading is overwriting the previous one.

But my need is to fill a read buffer in memory of let say a size of 1024. I fact to trigg an aquisition of 1024 points, all managed by dma. So the TX dma should loop on a 13 bytes buffer, but the RX dma should fill a 1024pts buffer.

from what I see now, even changing NORMAL to CIRCULAR mode on DMA tx, the first 13 bytes sent is what I expect, but nexts burts is what is following in memory. So the register to read value is no more the one I expect, then the LSM6 do not trigg the next measure.

Do we have a way to configure HAL_SPI_TransmitReceive_DMA() with a different buffer size for tx buffer and rx buffer?

or maybe to use HAL_SPI_Receive_DMA(), with the rx buffer size, but specifying the dummy bytes to send "register to read adress"??

Thank for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
baptor
Associate III

I finaly made a custom HAL function based on HAL_SPI_Receive_DMA : here is the prototype :

HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA_Custom(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t SizeTx, uint16_t SizeRx);

in the function itself, I changed sizes of transferts :

 /* Set the transaction information */

 hspi->ErrorCode  = HAL_SPI_ERROR_NONE;

 hspi->pTxBuffPtr = (uint8_t *)pTxData;

 hspi->TxXferSize = SizeTx;

 hspi->TxXferCount = SizeTx;

 hspi->pRxBuffPtr = (uint8_t *)pRxData;

 hspi->RxXferSize = SizeRx;

 hspi->RxXferCount = SizeRx;

Then now I have my bdma tx sending always the same buffer, and the bdma rx receiving SizeRx bytes.

Work well.

View solution in original post

1 REPLY 1
baptor
Associate III

I finaly made a custom HAL function based on HAL_SPI_Receive_DMA : here is the prototype :

HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA_Custom(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t SizeTx, uint16_t SizeRx);

in the function itself, I changed sizes of transferts :

 /* Set the transaction information */

 hspi->ErrorCode  = HAL_SPI_ERROR_NONE;

 hspi->pTxBuffPtr = (uint8_t *)pTxData;

 hspi->TxXferSize = SizeTx;

 hspi->TxXferCount = SizeTx;

 hspi->pRxBuffPtr = (uint8_t *)pRxData;

 hspi->RxXferSize = SizeRx;

 hspi->RxXferCount = SizeRx;

Then now I have my bdma tx sending always the same buffer, and the bdma rx receiving SizeRx bytes.

Work well.