I am programming the "Tiny RTC DS1307 " as sold on ebay.
It has two chips, one is the Maxim DS1307. I have some questions not clear from the manual.
- If you try to start/stop the clock you need to write to register 0 which is also the seconds register. But if you zap it then you lose your seconds count. I presume it is implied that when you do a stop, well you do not care what the seconds count is, and when you do a start, you should also send a new, valid seconds count.
But if you instead wanted to use it as a stopwatch, then you'd need to stop and start while maintaining the seconds count. I have therefore written my Stop() and Start() functions to first get the current value of seconds so that the subsequent write does not trash the seconds count. This works but it requires extra transfers on the I2C bus. Have I got it right or am I missing a clever trick? Here is my Stop and Start code:
void Tiny_RTC_DS1307_24C32::Stop()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
uint8_t bRet = Wire.requestFrom(DS1307_I2C_ADDRESS, 1);
byte bReg0 = Wire.read();
bReg0 |= 0x80;
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(bReg0);
Wire.endTransmission();
}
void Tiny_RTC_DS1307_24C32::Start()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
uint8_t bRet = Wire.requestFrom(DS1307_I2C_ADDRESS, 1);
byte bReg0 = Wire.read();
bReg0 &= 0x7f;
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(bReg0);
Wire.endTransmission();
}