SPI.transfer kills timer interrupt

I am just starting afresh with Arduino after several years break.

I am developing a project which uses Timer1 in CTC mode with interrupts. The project also has a MAX7219 connected to the SPI bus. The timer code works perfectly until I call SPI.transfer when the interrupt stops working.

Is there any way to prevent the SPI library from killing the timer interrupt or am I quicker writing my own SPI driver, which is fairly trivial stuff.

if you are calling SPI functions in the timer interrupt routine and the SPI interrupt is a lower priority than the timer it could cause the system to hang
when calling I2C functions in a timer interrupt routine I enable interrupts on entry, e.g.

//timer1 interrupt called every 20mSec - read BMP280 temperature copy to ring buffer
ISR(TIMER1_COMPA_vect){
      sei();                                            //allow interrupts

Thanks for replying, but that's not the reason. All my SPI calls are in the main loop and are polled. The only interrupt enabled is Timer1 CTC.

which arduino are you using?
what are you doing in the timer interrupt?
can you post code?

It's the Nano. Sorry I'm accessing the forum on my phone and can't upload the code at the moment. I'll post it as soon as I can get to the computer.

OK, here’s the interrupt code:

ISR(TIMER_COMPA_vect) {

flags |= STEP_FLAG;

digitalWrite(ledPin, digitalRead(ledPin) ^ 1);

stepCount++;
stepCount &= 15;

switch(stepCount) {
case 0:
OCR1A = timerDriveValue;
break;

case 8:
OCR1A = timerRecoveryValue;
break;

default:
break;
}
}

It works perfectly until I add a call to SPI.transfer to the loop code. Note that the SPI.transfer isn’t executed until a button is pressed, so I can see the LED flashing until it is pressed.

I hope that helps.

SPI/MAX7219 is easy to drive without library calls:

digitalWrite (ssPin, LOW);
SPDR = (registerAddress]);
    {nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;} // wait for the data to be clocked out
SPDR = (dataToWrite]);
    {nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;}
digitalWrite (ssPin, HIGH);


//and this at the top of the sketch
#define nop asm volatile ("nop")

Thanks Crossroads, I’ll give that a try.

Thanks again CrossRoads. That's fixed it, all working now.

I have been trying to find the libraries in Documents but I haven't been able to locate them. I wanted to see what the problem was with the SPI library. I'm using Windows 8.1.

Libraries are on the reference page, and in your IDE directories.