Reading critical I2C data
Posted: Tue May 18, 2021 2:30 pm
Hi All,
I'm testing a driver for an accelorometer/gyroscope.
There is a sequence in the driver which reads timestamp value during initialisation and correllates it to the ESP's RTC clock (system time), to calculate the drift between the two, so it can map timestamp data from the sensor to system time.
This is needed because there is a FIFO in the sensor which is read in bursts, and the data packets in the FIFO contain the timestamp information pair with the data. Normally when data accumulates in the FIFO and FIFO becomes full, it fires a GPIO interrupt, which triggers the ESP to read the FIFO empty.
In this case becuase the relation between the sensor timestamp and system time is established, we can process the read data properly.
This way I don't have to call I2C reads at a fixed frequency, which is good.
It is important that this relatively short calibration process is not dusturbed by anything, however the I2C drivers reliance on FreeRTOS make it difficult as I can not perform a read in critical section, because it causes a crash due to I2C interrupt and interrupt WDT triggering an abort()... or maybe I'm doing it wrong?
Is there a good way to do this somehow, without crashing, but still somewhat keeping the code execution protected?
This is done normally once on startup, when nothing else is running. Maybe vTaskSuspendAll() is enough to not let the scheduler mess with it?
Looking forward to read your opinions regarding this.
Thanks
Vader(Ben)
I'm testing a driver for an accelorometer/gyroscope.
There is a sequence in the driver which reads timestamp value during initialisation and correllates it to the ESP's RTC clock (system time), to calculate the drift between the two, so it can map timestamp data from the sensor to system time.
This is needed because there is a FIFO in the sensor which is read in bursts, and the data packets in the FIFO contain the timestamp information pair with the data. Normally when data accumulates in the FIFO and FIFO becomes full, it fires a GPIO interrupt, which triggers the ESP to read the FIFO empty.
In this case becuase the relation between the sensor timestamp and system time is established, we can process the read data properly.
This way I don't have to call I2C reads at a fixed frequency, which is good.
It is important that this relatively short calibration process is not dusturbed by anything, however the I2C drivers reliance on FreeRTOS make it difficult as I can not perform a read in critical section, because it causes a crash due to I2C interrupt and interrupt WDT triggering an abort()... or maybe I'm doing it wrong?
Is there a good way to do this somehow, without crashing, but still somewhat keeping the code execution protected?
This is done normally once on startup, when nothing else is running. Maybe vTaskSuspendAll() is enough to not let the scheduler mess with it?
Looking forward to read your opinions regarding this.
Thanks
Vader(Ben)