PDA

View Full Version : 12C fails on first attempt, then works fine...



brid0030
- 4th January 2018, 21:26
I'm trying to communicate with a Micro Crystal RV-1805-C3 real time clock using a PIC12LF1840. This RTC has a high impedance pin that can be employed to switch off everything but the clock and then power everything back up again when needed. So you can get a super low sleep current for the system (like 20 nA).

When the PIC powers up, the first thing I want it to do is read parameters from the clock on an I2C bus. I've found through experimentation that the first attempt to communicate with I2C consistently fails both for reading and writing. After that it works fine. I've tried adding things before the first I2C communication such as long pauses and simulated stop conditions, but they have no effect. There are two things that seem to work. First is just to insert a dummy I2C command addressed to a non-existing device (or just issue a read to the clock and ignore the results). Second is to have the clock implement a brief delay before it shuts down the PIC. That is, you have the clock wait for a period of 8ms after the last I2C command before shutting things down. Somehow this wait period enables the PIC to wake up and do I2C coms as usual. I have no idea why. I just have a pause following the go-to-sleep command to the clock.

Ideally I would like to have this system minimize its awake time. It's not a huge deal to have the dummy I2C command as a work around, but I would still like to understand what's going on. I haven't scoped the I2C lines yet, but I could if this this stumps the forum.

Dave
- 4th January 2018, 21:35
birg0030, Do you have the requisite resistor pull-ups on the SCL and SDA lines?

brid0030
- 4th January 2018, 23:28
birg0030, Do you have the requisite resistor pull-ups on the SCL and SDA lines?

I have 22K pull-ups in place. I know that value is a bit high, but slowing down the transmission rate does not help.

Scampy
- 5th January 2018, 11:16
I'm no expert, and don't understand the formula outlined in the datasheet http://www.ti.com/lit/an/slva689/slva689.pdf but it seems to suggest that lower value resistors are required. The example given for fast transmission at 3.3v is typically 1K, or around 5K (4.7K are traditionally the norm) for 5v operation

brid0030
- 5th January 2018, 17:56
I don't think it is the resistors. I've used 100k before and it's been OK. I also tried different values in parallel with the 22k resistors to bring the pullup values down. Issue remains.

I've done some more tweaking and I don't seem to have the same problem with two other I2C devices on the same bus. So the issue might be something particular to the RTC.