Go Down

Topic: Is it possible to use SPI in interrupt and 'regular' code (Read 409 times) previous topic - next topic

Nick Gammon


I understand your remark regarding "my sketch" but the question is of more general nature.


Oh well, if we are talking generally ...

http://www.gammon.com.au/interrupts

You can "guard" code by putting noInterrupts () ... interrupts ()  around it.

I presume you have working the need to set the appropriate SS lines, as you say it is more-or-less working.

Quote
This could mean for example that program execution jumps to the interrupt in the middle of a Serial.println()-statement.


Virtually anywhere. Some code is already guarded to make sure that variables are accessed atomically. You may also need to do that.

Just be aware that doing X when interrupts are off will defer X until interrupts are re-enabled. Plus a timer interrupt may be queued as well. You may be reducing the window of time in which X (plus timers etc.) are done so small that you run out of time.

CaptainJack

Gentlemen,

Thank you very much for the reply. I will study both the link and the library in further detail. The explanation in the link was exactly what I was looking for. The code is working fully, I'm just going over it again to see if I can simplify things.

Cheers !

Jack

ps @nick: that is an awfully big collection of notes you've got there, very nice !

Go Up