cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Master using HAL_SPI_TransmitReceive_DMA

Nabu .1
Associate

Hi everyone,

I am a new user of ST microcontroller. I am not familiar with DMA. 

Currently I am working on to pull the data from the AFE as slave using DMA method using CUBE generate code:

HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData,uint16_t Size).

I am able to get the correct value. 

My problem is when I tried to read the data continuously, I will get the error code. Is there anything that I need to care first before pulling another data?

example:  

state = SingleRegCommVerify(AFE_ConfigStart, &afe_read_buf[0], AFE_READ);//this will call HAL_SPI routine
if(state == COMM_DONE) //comm error
{
stat1 = afe_read_buf[0];
}//it will skip this 

state = SingleRegCommVerify(AFE_CalStart, &afe_read_buf[0], AFE_READ);
if(state == COMM_DONE)
{
stat2 = afe_read_buf[0];  //correct value
}

Thanks for the help.

-illa-

1 ACCEPTED SOLUTION

Accepted Solutions

You can use HAL_SPI_GetState() to read the current state.

// start operation
HAL_SPI_TransmitReceive_DMA(&hspi1, ...);
// wait for it to complete
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) {
}

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

HAL_SPI_TransmitReceive_DMA is a non-blocking call, which means it works in the background and takes time to complete. If you call it again before it is completed, it will return HAL_BUSY and not work.

If you feel a post has answered your question, please click "Accept as Solution".
Nabu .1
Associate

So, It means I need to wait longer? How do I know the process is complete? 

You can use HAL_SPI_GetState() to read the current state.

// start operation
HAL_SPI_TransmitReceive_DMA(&hspi1, ...);
// wait for it to complete
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) {
}

 

If you feel a post has answered your question, please click "Accept as Solution".