Best Communications Protocol to Send Data within Compare Match Interrupt

Greetings all,

I apologize if this topic has been covered, however I have searched HIGH and LOW and have not been able to find a clear answer to my conundrum. I am wondering what is the best comm protocol (I2C, SPI, CAN) to send data, between two Arduinos, within a compare match interrupt?

My application is this:

I would like to have one Arduino, call it Arduino1 performing a calculation, the output of that calculation will then be sent to a second Arduino, call it Arduino2, which will use the value to perform a second calculation. Arduino1 needs to send data to Arduino2 at a rate of 50 Hz, so I have set up a compare match interrupt on Arduino1 to send data at 50 Hz.

I have tried using I2C within the interrupt service routine (ISR) however that does not seem to be working. On some blog post a blogger hinted that I2C uses interrupts and wouldn't work within an ISR because interrupts are disabled within an ISR. Any thoughts?

Thanks

Thanks

That's right. SPI might be better, as SPI.transfer does not use interrupts. Plus, it is faster.

However at 50 Hz the compare match interrupt could set a flag, and in the main loop you test that flag and do the sending there.

Thanks Nick, I will try using SPI.