I wonder if it is me doing something wrong or it is a general thing. But does the use of the Wire library conflict with using Timer1 on a Nano?
If I perform the I2C communication outside an ISR then everything works flawlessly but if done inside the program crashes.
What I want to achieve is a simple, but interrupt controlled, setting of a control device. I have no need of reading anything via I2C. Below is a sample code.
If I comment out Wire.endTransmission(); the program continues to run but the device does not get the end of transmission thus does no do what it is supposed to.
Sorry, there is a response the first time and it is 0. So according to this everything works. I have also tried with endTransmission(true) but the program still halts.
I would sat that I need to send to the I2C device almost every time. So I cannot skip it. OK I could do a bit optimization but perhaps less than 10% of the time.
A note: If I do the same with SPI I have no problems.
The Wire library and I2C require interrupts to be enabled, but they are disabled within the ISR. Calling ControlDevice() from within the ISR will not work.
As Rob suggested, use the ISR to set a flag, and then check for that flag within the loop.
Pity that I2C needs interrupt when SPI doesn't. I will investigate my options 1) flag in ISR and evoke the ControlDevice() in the while loop and clear flag, or 2) I2C bit banging. I have plenty of time from interrupt to interrupt.