I have been trying to get to the bottom of using SPI during an interrupt with the teensy 3.X series. Documentation here suggests I need to configure the SPI library to be compatible with being used within an interrupt service routine. Ideally I have the isr service do a quick SPI transaction to read and update a volatile global variable, instead of simply checking a flag and requiring my code to always be polling to check if the spi transaction needs to be called for. The code would just need to call the global variable to get the most up to date version of it.
https://www.pjrc.com/teensy/td_libs_SPI.html is where I found some information,
and it suggests I need
Now, I'm trying to figure out where in my sketch I indicate I'm using interrupts, and what the "interrupt" argument is asking for. Currently, the SPI library is not explicitly "included" in the main .ino, because the adafruit MAX3156 library does the SPI transaction and calls for SPI. Does that mean I need to add the interrupt awareness to the MAX3156 library's SPI configuration sequence instead of my startup code?
Secondly, what does the information mean by taking as input the "interrupt" that will be triggering SPI communication? Am I naming a Pin? A timer? An isr function? Not sure what I put within SPI.usingInterrupts(?HERE?);
Right now I am trying to modify the adafruit MAX3856 thermocouple chip library to work in "continuous mode" in which the chip automatically reads the thermocouple temperature and pulls down the DRDY line on the breakout board to trigger an interrupt that reads the current available temperature reading. I am trying to do this on four instances of the MAX3156 library, representing the 4 MAX3156 breakout boards I'm working with. They each have a DRDY pin that toggles a different digital interrupt capable pin on a teensy 3.5.
The thing with Adafruit's default library is that it uses a "one shot" reading mode of the chip, and has a blocking 250mS requirement to the one shot reading mode. So with 4 sensors all my cpu time would be spend in a delay function.
I am open to learning why my desire to make the spi transaction in the isr routines is a bad idea. I could also write it so that the isr routine just flips a flag, for which my main program is responsible to check and then make the spi updates to the temperature variable. Also if this is an OK practice, I would be great to figure out what I'm missing to configuring SPI.usingInterrupts(interrupt) !
https://www.pjrc.com/teensy/td_libs_SPI.html is where I found some information,
and it suggests I need
Code:
SPI.usingInterrupt(interrupt)
If your program will perform SPI transactions within an interrupt, call this function to register the interrupt number or name with the SPI library. This allows beginTransaction() to prevent usage conflicts."
Now, I'm trying to figure out where in my sketch I indicate I'm using interrupts, and what the "interrupt" argument is asking for. Currently, the SPI library is not explicitly "included" in the main .ino, because the adafruit MAX3156 library does the SPI transaction and calls for SPI. Does that mean I need to add the interrupt awareness to the MAX3156 library's SPI configuration sequence instead of my startup code?
Secondly, what does the information mean by taking as input the "interrupt" that will be triggering SPI communication? Am I naming a Pin? A timer? An isr function? Not sure what I put within SPI.usingInterrupts(?HERE?);
Right now I am trying to modify the adafruit MAX3856 thermocouple chip library to work in "continuous mode" in which the chip automatically reads the thermocouple temperature and pulls down the DRDY line on the breakout board to trigger an interrupt that reads the current available temperature reading. I am trying to do this on four instances of the MAX3156 library, representing the 4 MAX3156 breakout boards I'm working with. They each have a DRDY pin that toggles a different digital interrupt capable pin on a teensy 3.5.
The thing with Adafruit's default library is that it uses a "one shot" reading mode of the chip, and has a blocking 250mS requirement to the one shot reading mode. So with 4 sensors all my cpu time would be spend in a delay function.
I am open to learning why my desire to make the spi transaction in the isr routines is a bad idea. I could also write it so that the isr routine just flips a flag, for which my main program is responsible to check and then make the spi updates to the temperature variable. Also if this is an OK practice, I would be great to figure out what I'm missing to configuring SPI.usingInterrupts(interrupt) !