DS1307RTC library question

Hello,

I'm using this library with a DS1307 module. It works fine.
As I checked the DS1307.cpp file, I found setCalibration and getCalibration functions.

If I get it right, setCalibration writes 0x07 address of the chip.

void DS1307RTC::setCalibration(char calValue)
{
  unsigned char calReg = abs(calValue) & 0x1f;
  if (calValue >= 0) calReg |= 0x20; // S bit is positive to speed up the clock
  Wire.beginTransmission(DS1307_CTRL_ID);
#if ARDUINO >= 100  
  Wire.write((uint8_t)0x07); // Point to calibration register
  Wire.write(calReg);
#else  
  Wire.send(0x07); // Point to calibration register
  Wire.send(calReg);
#endif
  Wire.endTransmission();  
}

DS1307 Datasheet marks 0x07 as the Control Register, the whole document doesn't mention Calibration Register at all.

What am I missing here?

Thanks in advance.

Your link to the datasheet does not work but this one does https://www.abelectronics.co.uk/docs/pdf/maxim-ds1307.pdf

It certainly looks like register 0x07 is used to output the square wave from the RTC and, as such, has nothing to do with calibration

probably poor historical choice in the function name. May be (far fetched?) it's meant to say that the SQW output could be used to assess the drift and calibrate/compensate later on in software...

just don't use that method and the compiler will get rid of it :slight_smile:

An interesting speculation, but using the SQW output to assess the drift assumes that you have a source of accurate data to compare it with. If so, then why not use that for timing instead or use it to set the RTC time at regular intervals :slight_smile:

Personally I suspect that the library is based on one for a different RTC and is simply left over from there

UKHeliBob:
Personally I suspect that the library is based on one for a different RTC and is simply left over from there

that's probably more likely

there are calibration techniques involving the measure the accuracy of the crystal oscillator (here for STM32F101xx and STM32F103xx RTC) which then requires storing a calibration information in a register. May be that's the origin indeed

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.