2024-12-02 07:26 AM
Hi,
I'm using Nucleo board with Stm32CubeIde and HAL library.
I have a periodic interrupt every 10 ms and I want to acquire data from 8 sensors with I2C bus each with a different address.
At the interrupt output I must already have all the data to copy into a circular buffer. For I2c requests I want to use DMA.
So I start eight requests at the same time, what I want to know is if the callback DMA interrupt is called in the same order as the request to have the correct data.
If not, how can I solve this problem?
Thank you in advance
Domenico
Solved! Go to Solution.
2024-12-03 06:18 AM
I dis some tests and these are results of the discussion.
1 - Request to the DMA are not buffered so it is not possible to make more than one request before the first one is finished.
2 - If I have to wait in the periodic interrupt for the end of the transfer, it makes no sense to use DMA when there are only a few bytes to receive. DMA setups take longer than just requesting. Even use the interrupt is overkill. The simplest solution is to use the blocking function.
Thank you all for your help in understanding the problem.
Domenico
2024-12-02 09:08 AM
Is it 8 devices on the same I2C bus? Then you cannot do this:
> So I start eight requests at the same time
You start one I2C process, whatever it takes, and when it finishes, you have to start the next one. That requires software intervention, usually the DMA triggers an interrupt when its transfer is done.
JW
2024-12-03 12:04 AM
Thanks for your reply.
Yes, these devices are on the same I2C bus with different address.
So you mean that it is possible to initiate eight DMA requests because they are buffered, but it is not guaranteed that the DMA callbacks , which is called eight times correctly, happen in the same order as the request?
Is this correct?
Domenico
2024-12-03 01:53 AM
You are interacting with a single physical interface, using a single DMA channel (or not using it - not really useful for I2C). What you really need is a software state machine implemented mostly in I2C MemRead callback routine, doing a scan of your sensors.
2024-12-03 02:47 AM
Why is it not useful to use DMA for the I2C bus transfers?
Ok, I can implement a state machine to handle all eight sensors.
I would like to know though, if I make eight requests with the same DMA and the same I2C bus, one after the other to the eight sensors with different addresses, is the DMA callback function called in the same order?
D
2024-12-03 06:18 AM
I dis some tests and these are results of the discussion.
1 - Request to the DMA are not buffered so it is not possible to make more than one request before the first one is finished.
2 - If I have to wait in the periodic interrupt for the end of the transfer, it makes no sense to use DMA when there are only a few bytes to receive. DMA setups take longer than just requesting. Even use the interrupt is overkill. The simplest solution is to use the blocking function.
Thank you all for your help in understanding the problem.
Domenico