Logging interrupts during writes!

Hi! I have an issue that i would like to know if there actually is any way of solving it that would mean i would not have to compromise (my guess is there isn't but you know, i thought i'd give it a shot here).

I want to write to an SD-card or memory or whatever, and i also have an interrupt routine running. Generally you want to turn of the interrupt possibility during the writing process to ensure that there is no packet loss etc, that's atleast what i've heard.

My question is:
Is there a way to log interrupt signals coming in on the interrupt pin i'm using during the writing process when i have interrupts turned off? (also not needing external hardware such as latches or microcontrollers)

In a sense, i want to be able to push a button during the writing process that triggers an interrupt immediatly after the writing process is over.

Even while interrupts are disabled, the interrupt flag is turned on when an interrupt event occurs.
The flagged interrupt occurs the moment you re-enable the interrupt.
But this means that if two or more same interrupt events occur during the prohibition period, the second and subsequent interrupt events will be ignored.

Also, if the interrupt routine is built correctly, it is unlikely that it will interfere with writing to the SD card.
In other words, it may not be necessary to turn off interrupts.

EDIT:
And in the first place, interrupts may use for writing to the SD card.
(Perhaps it depends on what library implements SPI transaction.)

1 Like

I'll add as well that I don't see how that very simple usage of interrupts would interfere with the process of writing to an SD card. Just keep the interrupt short, raise a flag like buttonPressed = true; and deal with the flag in the loop. Don't attempt to handle the button action within the ISR (unless it's an emergency stop button which is then a different discussion).

Buttons in general do not require ISR if your loop is not taking too long as a human press is often multiple tenths of a second, so you usually would not miss a press.

1 Like

Thank you!

Thank you for clearifying!!

My understanding is that all of the timing-critical events involved in writing to the card are handled by the SDI peripheral independently. So if it's in the middle of transmitting a byte to the card, it will continue with that operation right through any interrupt that occurs. And remember that the master provides the clock signal for transfers in both directions, so even if one clock phase was a little longer than normal, it shouldn't matter. So I don't think it's necessary to turn off interrupts during serial traffic so long as you're letting the hardware peripheral do it, and are not using software serial of some kind.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.