Skip to main content
Haifeng
Associate II
July 31, 2019
Question

HAL_I2C_Slave_Receive_DMA

  • July 31, 2019
  • 4 replies
  • 1731 views

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.

This topic has been closed for replies.

4 replies

John Craven
Senior
July 31, 2019

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
HaifengAuthor
Associate II
July 31, 2019

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
August 2, 2019

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

Piranha
Principal III
August 3, 2019

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.