CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

dsPIC33 I2C Hardware Issue
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
daveh



Joined: 30 Aug 2013
Posts: 17

View user's profile Send private message

PostPosted: Tue Dec 05, 2017 3:00 pm     Reply with quote

Thanks Ttelmah and temtronic for all your help!

I added this piece of code before my I2C communication to check for and deal with a SDA stuck low fault condition:
Code:
#bit I2C2EN_BIT = 0x0216.15      // I2CEN bit to enable/disable hardware I2C module
#define i2c2_SDA PIN_B5


if(!input(i2c2_SDA)){            // SDA stuck low - Fault Condition
    I2C2EN_BIT=0;                // disable I2C2 Hardware Module
    output_drive(i2c2_SCL);      // set SCL as output
    while(!input(i2c2_SDA)){     // Toggle clock line till fault clears
       output_toggle(i2c2_SCL);
       delay_us(1);
    }
    output_float(i2c2_SCL);      // set SCL as input
    I2C2EN_BIT=1;                // enable I2C2 Hardware Module
}
Ttelmah



Joined: 11 Mar 2010
Posts: 12507

View user's profile Send private message

PostPosted: Tue Dec 05, 2017 3:21 pm     Reply with quote

Looks good. Smile
daveh



Joined: 30 Aug 2013
Posts: 17

View user's profile Send private message

PostPosted: Wed Jan 10, 2018 12:35 pm     Reply with quote

So apparently when the hardware I2C module is enabled "input(i2c2_SDA)" will always read '0'. [Someone please correct me if I'm wrong]

So instead I'm using the following code which disables the hardware I2C before testing the pin:
Code:
#bit I2C2EN_BIT = 0x0216.15      // I2CEN bit to enable/disable hardware I2C module
#define i2c2_SDA PIN_B5


I2C2EN_BIT=0;                // disable I2C2 Hardware Module
if(!input(i2c2_SDA)){            // SDA stuck low - Fault Condition
    output_drive(i2c2_SCL);      // set SCL as output
    while(!input(i2c2_SDA)){     // Toggle clock line till fault clears
       output_toggle(i2c2_SCL);
       delay_us(1);
    }
    output_float(i2c2_SCL);      // set SCL as input
}
I2C2EN_BIT=1;                // enable I2C2 Hardware Module
Ttelmah



Joined: 11 Mar 2010
Posts: 12507

View user's profile Send private message

PostPosted: Wed Jan 10, 2018 12:51 pm     Reply with quote

It should read as normal.
If you look at the internal pin logic, the read path still remains connected when there is a peripheral connected.
daveh



Joined: 30 Aug 2013
Posts: 17

View user's profile Send private message

PostPosted: Wed Jan 10, 2018 1:25 pm     Reply with quote

I guess I'm confused then, if I have the following code it does not beep. If I comment out the first line then it beeps.
When I look with the scope both SDA and SCL are pulled high prior to this piece of code.
Code:
I2C2EN_BIT=0;                                // disable I2C2 Hardware Module
if(input(i2c2_SDA)==0) beep();               // SDA stuck low - Fault Condition
I2C2EN_BIT=1;                                // enable I2C2 Hardware Module
Ttelmah



Joined: 11 Mar 2010
Posts: 12507

View user's profile Send private message

PostPosted: Wed Jan 10, 2018 3:17 pm     Reply with quote

Implies the LAT bit is set to zero.
So when you disable the I2C, the line is then driven low. The read sees if momentarily as low, so beeps, at the same time as releasing the line.
daveh



Joined: 30 Aug 2013
Posts: 17

View user's profile Send private message

PostPosted: Thu Jan 11, 2018 10:50 am     Reply with quote

I'm sorry, maybe I wasn't clear. If I use the code as shown (which disables the hardware I2C module) then it doesn't beep which indicates the line is high as it should.

If however I comment out the first line (so I leave the hardware I2C module enabled). Then it beeps which indicates SDA is low but it is actually high on the scope.

So it seems to read correctly when the I2C hardware module is disabled but doesn't seem to read correctly when it's enabled.

Is it possible that the I2C hardware module prevents the tris bits from being changed by the input() command?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group