Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

DS1307 Clock Halt bit.

Status
Not open for further replies.

Pommie

Well-Known Member
Most Helpful Member
I have a DS1307 hooked up to an Arduino and I'm getting some odd readings, I was getting seconds reading way above 59.

My code (after modifying)
Code:
void getRTC(){
  uint8_t  myhour,mymins,mysecs,myday,mymonth,myyear;
  Wire.begin();
  Wire.beginTransmission(0x68);     //read the RTC.
  Wire.write(0);
  Wire.endTransmission(false);      //don't release the bus
  Wire.requestFrom(0x68,8);
  uint8_t temp = Wire.read();
  Serial.println(temp,HEX);
  temp&=0x7f;
  mysecs=BCD2dec(temp);
  mymins=BCD2dec(Wire.read());
  myhour=BCD2dec(Wire.read());
  Wire.read();      //location[3] not used = weekday
  myday=BCD2dec(Wire.read());
  mymonth=BCD2dec(Wire.read());
  myyear=BCD2dec(Wire.read())+2000;
  setTime(myhour,mymins,mysecs,myday,mymonth,myyear);
  Serial.print("Hour =");Serial.println(myhour);
  Serial.print("min  =");Serial.println(mymins);
  Serial.print("Sec  =");Serial.println(mysecs);
}
The modification is the and 0x7f on the seconds variable.

This is the printout I get in the serial window,
Code:
D8                //the HEX value returned from seconds register
Hour =3
min  =57
Sec  =58          //the seconds after the AND with 0x7f
D9
Hour =3
min  =57
Sec  =59
80
Hour =3
min  =58
Sec  =0
80
Hour =3
min  =58
Sec  =0
81
Hour =3
min  =58
Sec  =1
The fact the high bit of Seconds is set means the Clock Halt bit is set and yet, the clock is running.

Anyone got any ideas to explain this?

Mike.
Edit, for completeness, here's BCD2dec
Code:
uint8_t BCD2dec(uint8_t dat){
  return((dat>>4)*10+(dat&0x0f));
}
 
I'm guessing that the boards containing the DS1307 (from Ebay) don't use a genuine DS as the chip appears to completely ignore the CH bit.

Mike.
 
Possibly the wrong IC, an MCP7940??

That's a device I use; it's pin compatible with the 1307 by the look of it, and the first few registers are similar - except the high bit of the seconds register with than needs to be set to enable the oscillator..
 
The second contains the ST bit.. bit number 7 This must be cleared to run..

Sorry didn't read post properly..

The MCP4940 is a different address... I see what you mean though... The MCP has the halt set to run... The DS should be clear.

The only thing I can think of, is they didn't include pullups..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top