2
votes

I'm trying to read from multiple I2C slave devices using a dsPIC33 microcontroller.

I was hoping someone could advise me on the correct method to user a timer interrupt (in this case timer1) and collecting the I2C data.

So far I can collect data fine from the I2C slave devices by looping in a while loop, but since attempting to add a timer interrupt (so I can apply my own sampling rate rather than 'collect as fast as you can') my I2C software driver is getting stuck.

I've tried with a very low timer speed (1Hz at the moment) and I2C is on the standard 100KHz speed. The PIC is processing at 80MHz.

What is the correct method to use timers and I2C modules? I've had a look online and it seems it could be a matter of interrupt priority as when using timer1 I have an interrupt (I2C) within an interrupt (timer1), although no luck so far.

1

1 Answers

1
votes

It seems I managed to solve my own problem, and fairly quickly too.

Turned out it was an interrupt priority problem, I had previously had my timer1 set to priority 7 (highest):

IPC0bits.T1IP = 0b111; // Timer1 Interrupt priority level=7

Changing this to priority 1 solved the problem:

IPC0bits.T1IP = 0b001; // Timer1 Interrupt priority level=1

Hope this helps someone else that comes across this issue, my guess is that the different priorities conflict with the I2C interrupt.