Skip to content

Commit

Permalink
Implement support for the DS3232 clock chip
Browse files Browse the repository at this point in the history
  • Loading branch information
rweather committed May 25, 2012
1 parent 466b512 commit be14f5c
Show file tree
Hide file tree
Showing 8 changed files with 621 additions and 25 deletions.
1 change: 1 addition & 0 deletions doc/mainpage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ including support for configuring alarms and storing clock settings.
The default implementation simulates the time and date based on the value of
<tt>millis()</tt>.
\li DS1307RTC class that talks to the DS1307 realtime clock chip via I2C.
\li DS3232RTC class that talks to the DS3232 realtime clock chip via I2C.
\li \ref alarm_clock "Alarm Clock" example that uses the DS1307
realtime clock and the LCD library to implement an alarm clock.

Expand Down
15 changes: 8 additions & 7 deletions libraries/RTC/DS1307RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* then the contents of NVRAM will be cleared. Any previous contents
* will be lost.
*
* \sa RTC
* \sa RTC, DS3232RTC
*/

// I2C address of the RTC chip (7-bit).
Expand Down Expand Up @@ -106,10 +106,6 @@ DS1307RTC::DS1307RTC(I2CMaster &bus, uint8_t oneHzPin)
initAlarms();
}

DS1307RTC::~DS1307RTC()
{
}

/**
* \fn bool DS1307RTC::isRealTime() const
* \brief Returns true if the realtime clock is on the I2C bus; false if the time and date are simulated.
Expand Down Expand Up @@ -190,7 +186,7 @@ void DS1307RTC::readDate(RTCDate *value)
// RTC chip is not responding.
value->day = 1;
value->month = 1;
value->year = 2012;
value->year = 2000;
}
}

Expand Down Expand Up @@ -261,6 +257,11 @@ void DS1307RTC::writeAlarm(uint8_t alarmNum, const RTCAlarm *value)
}
}

int DS1307RTC::byteCount() const
{
return DS1307_ALARMS - DS1307_NVRAM;
}

uint8_t DS1307RTC::readByte(uint8_t offset)
{
if (_isRealTime)
Expand Down Expand Up @@ -289,7 +290,7 @@ void DS1307RTC::initAlarms()
alarm.flags = 0;
for (uint8_t index = 0; index < ALARM_COUNT; ++index)
writeAlarm(index, &alarm);
writeRegister(DS1307_I2C_ADDRESS, 0xB0 + ALARM_COUNT);
writeRegister(DS1307_ALARM_MAGIC, 0xB0 + ALARM_COUNT);

// Also clear the rest of NVRAM so that it is in a known state.
// Otherwise we'll have whatever garbage was present at power-on.
Expand Down
2 changes: 1 addition & 1 deletion libraries/RTC/DS1307RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class I2CMaster;
class DS1307RTC : public RTC {
public:
DS1307RTC(I2CMaster &bus, uint8_t oneHzPin = 255);
~DS1307RTC();

bool isRealTime() const { return _isRealTime; }

Expand All @@ -45,6 +44,7 @@ class DS1307RTC : public RTC {
void readAlarm(uint8_t alarmNum, RTCAlarm *value);
void writeAlarm(uint8_t alarmNum, const RTCAlarm *value);

int byteCount() const;
uint8_t readByte(uint8_t offset);
void writeByte(uint8_t offset, uint8_t value);

Expand Down
Loading

0 comments on commit be14f5c

Please sign in to comment.