ISRs, asyncio, threading question #15126
-
Hi, What is the best way to send a short message over I2C as fast as possible to a peripheral after an external interrupt has occurred?
Any tips in handling this single "realtime event" in a non-realtime application? Here some non-complete example code showing the 4 things I have tried already.
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
The STM32F4 has multiple DMA channels available. |
Beta Was this translation helpful? Give feedback.
-
Option 4: micropython.schedule will interrupt any running code except another scheduled routine. It will not wait for an asyncio coro to yield. So this option is really low latency, better than 1 to 3. The DMA option described above is probably even faster. |
Beta Was this translation helpful? Give feedback.
-
Ok thanks. Does anyone know what the dma=True really does in the pyb.I2C init call? I tried this and put the send call in the ISR but nothing happened, maybe I did something else wrong. Did anyone used that option before? |
Beta Was this translation helpful? Give feedback.
-
Using If ~3ms is too long, then DMA is probably the only solution. |
Beta Was this translation helpful? Give feedback.
The STM32F4 has multiple DMA channels available.
I'd prepare the entire DMA transfer to the I2C beforehand and use a hard IRQ Trigger.
Within that ISR I'd just trigger the DMA transfer.
It's hardly possible to make that any faster.