cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with specific I2C DMA setup on STM32U5

ruddy17
Visitor

Hello,

I am trying to implement the following: a timer (tim3) is set to PWM generation, outputting a pulse periodically. Its TRGO triggers the DMA channel to request I2C to initiate a read transaction, read 8 bytes and generate an event interrupt (TC probably) to process these data bytes. On the next PWM pulse the next 8 bytes should be read. Data should be put to a circular buffer (ideally 8 bytes long, so that data is just overwritten into the same memory buffer. Cycle should continue indefinitely.

I feel like this scenario should be implementable, however I don't seem to grasp how to set it up correctly. I have the timer generating pulses correctly, but no tinkering with GPDMA and I2C settings yields a working procedure, at best I manage to make I2C to trigger, but only read 2 bytes once and then not reacting to consecutive pulses. I don't ask to do my job for me, but at least could you confirm that it is doable and outline the correct way to set it up? Thx.

Here is how everything is set up now (pics attached) and how I start the cycle in the code:

HAL_I2C_Master_Receive_DMA(&hallSensorI2C, 0xC0, tempBuf, 8);
HAL_TIM_PWM_Start_IT(&trayTimer, TIM_CHANNEL_2);
1 REPLY 1
ruddy17
Visitor

After some meditating over the reference manual, I got an idea. I think, to initiate a new transaction, I need to update I2C CR2 register each time. So, I think I need to make a linked list DMA queue, with a node writing something into CR2, and the next node to actually request Rx. Does it sound correct?