cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_Slave_Receive_DMA

Haifeng
Associate II

When I use the I2C DMA receive mode, how could I know the data has been received? I found if I use the delay to check the data, it seems it could work, but actually, we don't know when the data will be coming. so there should have a mechanism to tell the user app that the data has been received. I tried to use the call back function (eg. HAL_I2C_SlaveRxCpltCallback() ), but it seems no one could be tracing in.

4 REPLIES 4
John Craven
Senior

You can check the CNDTR register of the DMA channel you are using.

you can use:

__HAL_DMA_GET_COUNTER(hi2cN.hdmarx);

or

hi2cN.hdmarx->Instance->CNDTR;

If nothing has been received it will hold the dma rx buffersize - 1

it will count down to zero as the buffer fills.

Haifeng
Associate II

The interesting thing if we’re going to use DMA, it also means we don’t want to pending with polling status, just want to do something else, and after DMA completion, it could send out a semaphore to back.

John Craven
Senior

DMA rx complete is not going to help much unless you have fixed message size.

Piranha
Chief II

Normally it can be done by combining DMA/interrupt buffer's "Rx complete" with I2C peripherals STOP interrupt. With HAL... Well, it's one more reason to not use that crippled and bloated bug library.