View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19954
|
|
Posted: Wed Oct 01, 2025 9:25 am |
|
|
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
|
|
Posted: Wed Oct 01, 2025 9:37 am |
|
|
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
|
|
Posted: Wed Oct 01, 2025 9:57 am |
|
|
@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
|
|
Posted: Wed Oct 01, 2025 11:07 am |
|
|
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
|
|
Posted: Wed Oct 01, 2025 8:23 pm |
|
|
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
|
|
Posted: Thu Oct 02, 2025 6:02 am |
|
|
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'.... |
|
 |
|