using i2c library with timer0 interrupt (ESP8266)

I need to read some values from I2C , on strict time. SO I am using timer0 ISR.

  noInterrupts();
  timer0_isr_init();
  timer0_attachInterrupt(timer0_ISR);
  timer0_write(ESP.getCycleCount() + 80000000); //80Mhz -> 80*10^6 = 1 second
  interrupts();
void timer0_ISR (void){
  
  tog = !tog;
  digitalWrite(LED_BUILTIN, tog);
  // Set-up the next interrupt cycle
   timer0_write(ESP.getCycleCount() + (80000000)/1); //80Mhz -> 80*10^6 = 1 second
}

LED toggles very accurately. But when I use it with the I2C library. It doesn't give correct results.

  void timer0_ISR (void){
   readI2CPort();// this communicates on i2c.
  // Set-up the next interrupt cycle
   timer0_write(ESP.getCycleCount() + (80000000)/1); //80Mhz -> 80*10^6 = 1 second
}

I2C depends on interrupts so it must not be called from interrupt context.

Thanks,

Let me figure out other ways.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.