I learned, that SPI-code uses interrupts. So is it true then, that I can't use SPI related code inside an ISR?
Background: I want to capture one or more revolution speeds with an MCP23S17. I rewired the interrupt lines to INT1 and INT2 accordingly to get the interrupts at the Arduino.
I thought it was good to fetch the port registers from the MCP23S17 inside the ISR, but this apparently doesn't work.
Is the only thing I can do in my ISR set a flag for another test in the main loop? And let a routine called from lood() then poll the registers from the port expander? This opposes the idea to fetch the relevant data which issued the interrupt ASAP.
1 Answer 1
SPI doesn't use interrupts. It references the interrupt flag to know if a transfer has been completed, but it doesn't actually have interrupts enabled:
SPDR = data;
asm volatile("nop");
while (!(SPSR & _BV(SPIF))) ; // wait
return SPDR;
It should be perfectly possible to use SPI within the interrupt - indeed there is portions of the SPI API that deal specifically with this - see https://www.arduino.cc/en/Reference/SPIusingInterrupt for instance.
-
Ok, I missed that. Then there must be another thing I apparently have botched...Ariser– Ariser08/20/2015 09:53:37Commented Aug 20, 2015 at 9:53
SPI.transfer()
. I learned, that SPI-code uses interrupts. - where did you learn that?apparently doesn't work.
- I hate that expression. What happened? What did you expect to happen? In what way did they differ?