2
\$\begingroup\$

Because I've seen HAL_TIM_Base_DMA_START() in the STM32F7 HAL timer library, I though maybe it is possible to, for example, call HAL_TIM_Base_DMA_START() and timer continually requesting DMA to transmit data to I2C preiodically without CPU activity?

\$\endgroup\$
4
  • \$\begingroup\$ What would this achieve? The I2C HAL can already use DMA to do I2C data transfers without CPU intervention (after the transfer is properly set up, that is). \$\endgroup\$
    – Justme
    Mar 1 at 13:31
  • \$\begingroup\$ @Justme But you must call it, but with timer you even don't need to call it, since it will be autocalled periodically and precisely. \$\endgroup\$ Mar 2 at 12:17
  • \$\begingroup\$ To put things in context, you have a 480 MHz MCU, and the highest raw I2C speed is 1 MHz tops. A byte is transferred at 111 kHz rate. You can use standard polling, interrupt or DMA interface. If the device you want to communicate with stretches the clock to slow down transfers, then your forced DMA will not work. It just makes no sense to use timer events to manually trigger I2C DMA transfers. Even if it is possible. \$\endgroup\$
    – Justme
    Mar 2 at 12:46
  • \$\begingroup\$ @Justme ie MCP4725 doesn't slow by stretch and DMA will work, but higher speed will cuse it to not work them manually must be care of speed control of timer. \$\endgroup\$ Mar 2 at 13:06

2 Answers 2

0
\$\begingroup\$

No, because how would the timer know anything about how to control the I2C peripheral to do something over a DMA channel. At most you can send bytes at a certain rate by triggering a DMA transmission by using a timer but the I2C transaction needs to be preconfigured to that point beforehand.

I2C transactions do support DMA and you can use timer interrupts to start I2C transactions which can do the transmission of the data phase with DMA in the background.

\$\endgroup\$
4
  • \$\begingroup\$ You could maybe send the start/adress then transmist other block without start and stop by timer to ... , for example fast ADC? \$\endgroup\$ Mar 2 at 12:21
  • \$\begingroup\$ In theory, if you want, you can do it as explained in my answer. The point is, even if possible in theory, there is no practical use case. You have a 480 MHz CPU and max transfer rate of 111 kilobytes per second, with the overhead of the bytes needed to address something in a chip. \$\endgroup\$
    – Justme
    Mar 2 at 13:41
  • \$\begingroup\$ My effort is not to maximize communication throput but is to maximize CPU processing power. \$\endgroup\$ Mar 3 at 6:47
  • \$\begingroup\$ If you already are afraid that I2C takes too much CPU time even with using standard DMA transfers initiated by I2C peripheral, it means you already have the wrong CPU. \$\endgroup\$
    – Justme
    Mar 3 at 7:50
0
\$\begingroup\$

Well - you could configure a timer to trigger a DMA to write bytes to the I2C peripheral - but it's unlikely that this would result in anything useful.
A successful I2C transaction requires Start & Stop conditions, possible Restarts, often Ack checks, etc - none of which would easily be managed with just timer-driven DMA sending bytes to the I2C.

You could configure a Timer such that its interrupt begins the I2C transaction (sends the Start bit) and gets it running to the point where you now only need to send a block of data, and then configure the DMA to send that data to the I2C peripheral ,- but you wouldn't involve the timer there - you would configure the I2C peripheral to trigger the DMA directly whenever it's ready for a new byte.
Then at the end you'd need to complete the transaction by sending a Stop bit, probably triggered by the DMA interrupt telling you that the data block is complete.

\$\endgroup\$
6
  • \$\begingroup\$ You could maybe send the start then transmist other block without start and stop by timer to for example fast ADC? \$\endgroup\$ Mar 2 at 12:20
  • \$\begingroup\$ What does it buy you to use the timer to trigger the DMA to copy a byte to the I2C when you could just have the I2C trigger the DMA directly whenever it needs a new byte to send? \$\endgroup\$
    – brhans
    Mar 2 at 12:51
  • \$\begingroup\$ Everytime we need to send adress. At least we need to think about it to where to place it's trigger in main app or in timer. But by timer+adc it will become quiet. Also I2c was an example. in this way we can have stable constatnt speed communication through DMA. But we must be aware that everything have both pros and cons. \$\endgroup\$ Mar 2 at 13:10
  • \$\begingroup\$ Sure, using a timer will give you a consistent period between one byte and the next, but that is very rarely a requirement in I2C communication. I've been doing this for decades and have never yet come across a project where that would have been needed. \$\endgroup\$
    – brhans
    Mar 2 at 13:16
  • \$\begingroup\$ I could imagine a case where maybe your microcontroller has a silicon bug preventing you from triggering the DMA directly from the I2C - maybe there you could use a timer to trigger the DMA instead ... \$\endgroup\$
    – brhans
    Mar 2 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.