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 CCS Technical Support

PIC24EP512GP806 - I2C not working after sleep/wake-up
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
Ttelmah



Joined: 11 Mar 2010
Posts: 19954

View user's profile Send private message

PostPosted: Wed Oct 01, 2025 9:25 am     Reply with quote

The point on i2c_init, is you really need to turn the peripheral off before
you sleep. so i2c_init(FALSE) before the sleep, and then wake it up again
when it wakes.
benoitstjean



Joined: 30 Oct 2007
Posts: 590
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Oct 01, 2025 9:37 am     Reply with quote

UPDATE:

Two issues:

The MPL3115 altimeter unit kept SCL low after being checked for altitude but every subsequent transactions still worked until MCU was put to sleep. At wake-up, that pin was still low therefore saw the I2C as not initialized. I added code to force a reset followed by a sleep of the MPL3115 and that brought the SCL pin back-up.

However, the second issue is strange:

At boot time, I do the following to check if I2C is connected to devices:

Code:
   // force SDA and SCL to low
   output_low( PIN_G3 );
   output_low( PIN_G2 );
   
   delay_ms( 100 );

   // force SDA and SCL to floating
   output_float( PIN_G3 );
   output_float( PIN_G2 );

//   delay_ms( 100 );

   // Read pin values
   bool TEST_SDA = input( PIN_G3 );
   bool TEST_SCL = input( PIN_G2 );


Based of the values of TEST_SDA and TEST_SCL, if both high, it means that pull-ups are there, therefore initialize the sensors.

This works at standard boot time but for whatever reason, when the device wakes-up, I see on my logic analyzer that these two lines are high but the MCU reads them as low.

So the workaround for that is that I check the .IsInitialized flag of both the CODEC and altimeter. Since these flags remain as-is when going to sleep - e.g. if they are both true, then on wake-up, they are still true so I added a condition in the if statement to check if TEST_SDA and TEST_SCL are high or if .IsEnabled are both true.


At regular power-up or after a reset_cpu, TEST_SDA and TEST_SCL are high but both .IsEnabled are low.

At wake-up from sleep, TEST_SDA and TEST_SCL both read low but .IsEnabled are high since they were initialized previously before going to sleep.

Anyways, it's a workaround for now until I figure-out why both lines are high as see on my analyzer but why the MCU reads them as low (on top of both having pull-ups)...

So all appears to be working as expected now.

Ben
benoitstjean



Joined: 30 Oct 2007
Posts: 590
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Oct 01, 2025 9:57 am     Reply with quote

@TTelmah

Never thought of even trying I2C_init( FALSE ) before going to sleep. I guess I was trying to understand and try too many things at once.

As much as the docs say that it disables I2C, it is not explicitly indicated to call it if going to sleep. I don't recall reading in the MCP docs that I2C must be turned-off before going to sleep either.

Anyhow, everything works as expected after waking-up.

Thanks.

Ben
Ttelmah



Joined: 11 Mar 2010
Posts: 19954

View user's profile Send private message

PostPosted: Wed Oct 01, 2025 11:07 am     Reply with quote

It shouldn't be needed. The peripheral should keep it's configuration.
However disabling it and then re-enabling 'makes sure'. The SCL being
held low by a peripheral means something is wrong in the transaction
you are using to this. It'd normally indicate the peripheral is not ready
to receive data. The device will hold it low for a short time when asked
to perform certain operations, but it should not be for long.
newguy



Joined: 24 Jun 2004
Posts: 1924

View user's profile Send private message

PostPosted: Wed Oct 01, 2025 8:23 pm     Reply with quote

The altimeter is likely holding SCL low because whatever the last I2C transaction before the processor goes to sleep is likely at fault. Is it possible the processor is sleeping before an I2C transaction finishes properly?
Ttelmah



Joined: 11 Mar 2010
Posts: 19954

View user's profile Send private message

PostPosted: Thu Oct 02, 2025 6:02 am     Reply with quote

Yes, that is exactly my thought. It will hold it low for a short time when
asked to take a reading for example. Going to sleep while this is happening
would be distinctly 'dubious'....
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