I got back to this topic, because I had problem on i2c and timer irq conflict.
The SD Card data logger worked well for many hours as inteded and planned using the earlier info in this topic.
There were two i2c devices used: INA226, RTC DS3231.
I used as it was described earlier: timer on irq priority level 2, and we know i2c is on level 3.
Code: Select all
The logger is reading and buffering the INA226 current and voltage sensor data within the timer interrupt task:
Code: Select all
void __attribute__((interrupt)) isr()
reg3 = ina.readBusVoltage(); //read the i2c sensor
reg4 = ina.readShuntCurrent();
//calculation and storing in the buffer code here
the execution time of the irq task was max 2.5 ms, and the timer has 10ms interval.
I have had a paralel 20x4 lcd, now I had to change to i2c lcd due to the fact I need more io pins.
After installing the i2c LCD the system was freezing on the display operation.
If the irq has been disabled, the display was working.
In the earlier version the RTC was read every sec once, there was no other action on the i2c bus outside the irq task.
In the new version the LCD refresh time is 100ms, plus the RTC reading as was before.
I have to admit, there were sometimes veird characters on the display on the time displaying area, so it has problems also in the earlier version but was not freezing the system.
When I arranged the timer interrupt only to set a flag, and polling the flag in the main loop(), executing the same code when the flag set, then it started to work.
I suppose two i2c cycles are overlaping somehow. Or what is the answer?
In my case the polling solution doesn't make any functional problem, because I am reading averaged value from the INA226, and the PIC32 makes short loop().
So a little sampling jitter probaly makes no or minor difference.
But in applications where the sampling is critical you have to act immediately within the irq task.
What could be the solution if you have multiple i2c devices?
Otherwise in this case I don't need the timer interrupt anymore, a micros() polling would be simpler solution.