Answer the question
In order to leave comments, you need to log in
Process and interrupt management in the stm32f4 microcontroller
As one program developed, the following problem arose:
Several sensors are connected to the I2C line. Let it be sensor "A" and sensor "B".
I received an interrupt from the USB - let's say a command from the computer to which the microcontroller is connected to pull the calibration data from sensor "A". This interrupt has a low priority. Let 3. The handler connected via I2C, and began to pull data from there. And at this moment, an interrupt comes from sensor "B" with a higher priority. 2 for example. Like, new dimensions are ready, take it. And the execution of the program jumped into the handler.
And along the line at that time data from "A" was transmitted. Naturally, the handler will try to connect to "B" and pick up the latest data, and make trouble on the line.
Of course, you can interrupt communications with "A" in the handler by sending a stop bit, and connect to "B", and then take the data from it. But then I will lose data from sensor "A", plus when control returns to handler "A", it will find that communication with "A" is suddenly closed. I would like the interrupt from B not to bother the handler A for nothing, but to wait for its turn.
It would be possible, of course, to assign the same priorities to interrupts "A" and "B", but then any secondary tasks requested by the computer via usb will interfere with the collection of data from sensors, which is not good.
That bish should be yielded only when the I2C line is busy.
I hope it's not too messy.
Answer the question
In order to leave comments, you need to log in
I have not worked with STM32 for a very long time, but usually DMA and translation of irq to soft-irq solve such things. The idea is to get an interrupt from USB - leave it "for later" in the form of a softirq handler, and write data from i2c directly to memory via DMA. When data collection is complete, handle all pending interrupts in order.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question