On an ESP8266 NodeMCU, in loop(), reading a BMP180 temperature and pressure is fine. When the DS3234 RTC triggers at 1Hz the ISR is triggered fine and I can read the date/time from the DS3234 in the ISR:
void ICACHE_RAM_ATTR timeInterruptFunction();
The issue is if I read temperature/pressure from the ISR triggered by the DS3234 the pressure is fine but the temperature is 103C instead of 20C.
Is there anything "special" about ISRs that might cause reading other sensors to get odd data back? I the ISR fires at 1Hz, so once a sec which should be enough time to read the date/time and temp/pressure. The only thing that isn't working is the temp. Put it back in loop() and it's fine.
Not using libraries. I2C and SPI direct.
I came across reading from I2C inside ISR on M0 Pro which has the advice:
Use the ISR to set a flag indicating that it's time to read the sensors. Then, pick up that flag in the loop() function and do your I2C operations there with interrupts enabled. Don't forget to clear the flag.
which seems sensible. It seems all interrupts are disabled when an ISR is run so I should just flag to the main code in loop() that it's time to read the sensors and still use an ISR from the RTC to orchestrate it.
Is there anything "special" about ISRs that might cause reading other sensors to get odd data back?
Variables that are updated in an ISR and used by code outside of it should be declared volatile to warn the compiler to store the values in a way that can be accessed outside of the ISR
thanks for that, makes a lot of sense.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.