I use the latest version of the SoftwareI2CBus which is part of the firmware of the CerbuinoBee firmware.
I have a problem reading out the DS3231. The read-function shows data that is out of sync with the internal registers (I see however valid DS3231 values).
In order to syncronise I would like to have access to the clock and data signal, but the driver prevents access to the pins…or…
Cpu.Pin SCA = GHI.Pins.Generic.GetPin('B', 3); //pull up resistor attached
Cpu.Pin SDA = GHI.Pins.Generic.GetPin('B', 4); //pull up resistor attached
SoftwareI2CBus Rtc1 = new SoftwareI2CBus(SCA, SDA);
Rtc1.CreateI2CDevice(0x68); //address slave
byte[] Wbuf = {0x00,0x00,0x15,0x1,0x01,0x11,0x14}; //set initial values DS3231: seconds, minutes,hours, dow, dom, month, year after 2000
byte[] Rbuf = new byte[30];
int Wd , Rd = 0;
Rtc1.WriteRead(0x68, Wbuf, 0x00, Wbuf.Length, Rbuf, 0, 0x00, out Wd, out Rd);
while (1 == 1)
{
Wd = Rd = 0;
// force DS3231 to an initial state (see quote from data sheet
Rtc1.WriteRead(0x68, Wbuf, 0, 0, Rbuf, 0x0, 0x13, out Wd, out Rd);
for ( int i=0; i< 0x13; i++ ) {
int BcdLow, BcdHigh = 0;
BcdHigh = (Rbuf[i]>>4) & 0x0f;
BcdLow = (Rbuf[i]) & 0x0f;
Debug.Print("Reg("+ i.ToString() + ") = "+ BcdHigh.ToString("D1") + BcdLow.ToString("D1"));
Thread.Sleep(1000);
}
}
QUOTE datasheet DS3231:
When the microcontroller
resets, the DS3231 I2C interface may be placed into a
known state by toggling SCL until SDA is observed to
be at a high level. At that point the microcontroller
should pull SDA low while SCL is high, generating a
START condition[quote]