Continue to Site

# DS1307 Clock Halt bit.

Status
Not open for further replies.

#### Pommie

##### Well-Known 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.write(0);
Wire.endTransmission(false);      //don't release the bus
Wire.requestFrom(0x68,8);
Serial.println(temp,HEX);
temp&=0x7f;
mysecs=BCD2dec(temp);
Wire.read();      //location[3] not used = weekday
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));
}

#### Pommie

##### Well-Known Member
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.

#### rjenkinsgb

##### Well-Known Member
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..

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
The second contains the ST bit.. bit number 7 This must be cleared to run..

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.

Replies
0
Views
364
Replies
0
Views
309
Replies
0
Views
527
Replies
0
Views
414
Replies
0
Views
496