Go Down

Topic: timer interrupt (Read 785 times) previous topic - next topic


i have some code that communicate over i2c with a sensor.
Sometimes the sensor stop working and the code stay locked in the i2c function.
Now i want use an interrupt timer, it has to be launched at least every seconds, and don't modify any prescaler etc.. because i need the timers for external library.
it will look at a variable that is incremented every loop(), and if the variable is >0 all is fine, otherwise it will reset the sensor (turn it off and restart communications?)
i've tried:

Code: [Select]

void setup(){
  TIMSK2 |= B00000100;
unsigned long time = micros();
void loop(){

ISR(TIMER2_OVF_vect) {

but nothing happen... help please?
Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino


Feb 03, 2011, 02:00 am Last Edit: Feb 03, 2011, 02:02 am by Graynomad Reason: 1
It looks like you're setting the OCIE2B bit (output compare), try setting TOIE2 (overflow, 0000001).

Also try using nmemonics

TIMSK2 |= (1<<TOIE2);

And "time" should be volatile if you ever start using it outside the ISR.
Rob Gray aka the GRAYnomad www.robgray.com

Go Up