Use timer interrupt to reset I2C

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
bakerj
Posts: 28
Joined: 21 Sep 2015 01:06

Use timer interrupt to reset I2C

#1 Post by bakerj » 21 Apr 2021 22:58

I have two PIC32 devices communicationg using the built-in I2C routines provided in the MikroE compiler. I am having an issue where the I2C master in some cases will hang. I am trying to use a timer1 interrupt to act as a timeout for the I2C module. Basically am setting a flag right before calling an I2C read/write and starting timer1. In the timer1 ISR I check the elapsed time and if its too long I rest the I2C by re-issuing the command I2C_init.

I have not gotten this to work and my question to the forum is "should this work in principle?". I don't want to keep working at this if its a dead end. Thanks.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Use timer interrupt to reset I2C

#2 Post by filip » 13 May 2021 13:17

Hi,

Why don't you use I2C_SetTimeoutCallback function from the I2C library, it will basically do the same thing but without interrupts ?
Please have a look at the I2C Library chapter in the help file for more information.

Regards,
Filip.

Post Reply

Return to “mikroBasic PRO for PIC32 General”