Conflict using SPI library in and out a timer interrupt

xarolium

Member
Hi guys,

I'm programming an hardware step sequencer and i need to use SPI.transfer in a timer interrupt and out too.
when timer interrupt appair the program stop and freeze.
I try to use SPI.usingInterupt() function but i don't know timer interrupt number.
Somebody ever use SPI in timer interrupt ?

Thank you for your help
Code:
ISR(TIMER1_COMPA_vect) { CountPPQN(); }


void CountPPQN()
{
  if (ppqn++ >= 96) ppqn = 1;
  
  if (isRunning){
    if(ppqn%4 == 0){
     TRIG_CS_LOW;
     SPI.transfer(byte(value >> 8));
     SPI.transfer(byte(value));
     TRIG_CS_HIGH;
      if(curStep++ == 16) curStep = 1;
    }
  }
}

Code:
////////////////////////Setup//////////////////////
void setup()
{

  InitIO();
  InitStepButtonCounter();
  InitConfigButtonCounter();
  TimerStart();

#if DEBUG
    Serial.begin(9600);
#endif
  sei();
}

////////////////////////Loop///////////////////////
void loop()
{
  SW_CS_HIGH;
  tempDin[0][1] = SPI.transfer(0);
  tempDin[1][1] = SPI.transfer(0);
  tempDin[2][1] = SPI.transfer(0);
  tempDin[3][1] = SPI.transfer(0);
  tempDin[4][1] = SPI.transfer(0);
  SW_CS_LOW; 
}
 
On AVR, SPI.usingInterrupt() can't support every individual type of interrupt, so I put in a fallback mode which is selected by any number larger than the highest known interrupt.

I know this because I created SPI transactions about 2 years ago, when numerous people using Teensy with multiple SPI chips had compatibility issues. I contributed the code to Arduino, so even if you're not using Teensy, if you have an AVR or SAM based Arduino, you're using the SPI transaction code I contributed. I'm pretty familiar with how it works!
 
Back
Top