2024-10-06 11:35 PM
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-
Solved! Go to Solution.
2024-10-07 06:35 PM
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) {
}
2024-10-07 05:07 AM
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.
2024-10-07 06:25 PM
So, It means I need to wait longer? How do I know the process is complete?
2024-10-07 06:35 PM
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) {
}