Skip to content

Commit bb7c31a

Browse files
author
JChristensen
committed
Add getEUI64() function, which converts the EUI-48 ID from an MCP79411 to EUI-64.
1 parent fb81547 commit bb7c31a

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

MCP79412RTC.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*----------------------------------------------------------------------*
2-
* MCP79412RTC.cpp - Arduino library for the Microchip MCP79412 *
3-
* Real-Time Clock. This library is intended for use with the Arduino *
2+
* MCP79412RTC.cpp - Arduino library for the Microchip MCP7941x *
3+
* Real-Time Clocks. This library is intended for use with the Arduino *
44
* Time.h library, http://www.arduino.cc/playground/Code/Time *
55
* *
66
* This library is a drop-in replacement for the DS1307RTC.h library *
77
* by Michael Margolis that is supplied with the Arduino Time library *
8-
* above. To change from using a DS1307 RTC to an MCP79412 RTC, it is *
8+
* above. To change from using a DS1307 RTC to an MCP7941x RTC, it is *
99
* only necessary to change the #include statement to include this *
1010
* library instead of DS1307RTC.h. *
1111
* *
1212
* In addition, this library implements functions to support the *
13-
* additional features of the MCP79412. *
13+
* additional features of the MCP7941x. *
1414
* *
1515
* Jack Christensen 29Jul2012 *
1616
* *
@@ -337,6 +337,7 @@ void MCP79412RTC::calibWrite(int value)
337337

338338
/*----------------------------------------------------------------------*
339339
* Read the unique ID. *
340+
* For the MCP79411 (EUI-48), the first two bytes will contain 0xFF. *
340341
* Caller must provide an 8-byte array to contain the results. *
341342
*----------------------------------------------------------------------*/
342343
void MCP79412RTC::idRead(byte *uniqueID)
@@ -348,6 +349,28 @@ void MCP79412RTC::idRead(byte *uniqueID)
348349
for (byte i=0; i<UNIQUE_ID_SIZE; i++) uniqueID[i] = i2cRead();
349350
}
350351

352+
/*----------------------------------------------------------------------*
353+
* Returns an EUI-64 ID. For an MCP79411, the EUI-48 ID is converted to *
354+
* EUI-64. For an MCP79412, calling this function is equivalent to *
355+
* calling idRead(). For an MCP79412, if the RTC type is known, calling *
356+
* idRead() will be a bit more efficient. *
357+
* Caller must provide an 8-byte array to contain the results. *
358+
*----------------------------------------------------------------------*/
359+
void MCP79412RTC::getEUI64(byte *uniqueID)
360+
{
361+
byte rtcID[8];
362+
363+
idRead(rtcID);
364+
if (rtcID[0] == 0xFF && rtcID[1] == 0xFF) {
365+
rtcID[0] = rtcID[2];
366+
rtcID[1] = rtcID[3];
367+
rtcID[2] = rtcID[4];
368+
rtcID[3] = 0xFF;
369+
rtcID[4] = 0xFE;
370+
}
371+
for (byte i=0; i<UNIQUE_ID_SIZE; i++) uniqueID[i] = rtcID[i];
372+
}
373+
351374
/*----------------------------------------------------------------------*
352375
* Check to see if a power failure has occurred. If so, returns TRUE *
353376
* as the function value, and returns the power down and power up *

MCP79412RTC.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*----------------------------------------------------------------------*
2-
* MCP79412RTC.h - Arduino library for the Microchip MCP79412 *
3-
* Real-Time Clock. This library is intended for use with the Arduino *
2+
* MCP79412RTC.h - Arduino library for the Microchip MCP7941x *
3+
* Real-Time Clocks. This library is intended for use with the Arduino *
44
* Time.h library, http://www.arduino.cc/playground/Code/Time *
55
* *
66
* This library is a drop-in replacement for the DS1307RTC.h library *
77
* by Michael Margolis that is supplied with the Arduino Time library *
8-
* above. To change from using a DS1307 RTC to an MCP79412 RTC, it is *
8+
* above. To change from using a DS1307 RTC to an MCP7941x RTC, it is *
99
* only necessary to change the #include statement to include this *
1010
* library instead of DS1307RTC.h. *
1111
* *
1212
* In addition, this library implements functions to support the *
13-
* additional features of the MCP79412. *
13+
* additional features of the MCP7941x. *
1414
* *
1515
* Jack Christensen 29Jul2012 *
1616
* *
@@ -130,6 +130,7 @@ class MCP79412RTC
130130
int calibRead(void);
131131
void calibWrite(int value);
132132
void idRead(byte *uniqueID);
133+
void getEUI64(byte *uniqueID);
133134
boolean powerFail(time_t *powerDown, time_t *powerUp);
134135
void squareWave(uint8_t freq);
135136
void setAlarm(uint8_t alarmNumber, time_t alarmTime);

ReadMe.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ Jack Christensen Sep 2012
66
![CC BY-SA](http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by-sa.png)
77

88
## Introduction ##
9-
**MCP79412RTC** is an Arduino library that supports the Microchip MCP79412 Real-Time Clock/Calendar. It is intended to be used with the [Arduino Time library] (http://www.arduino.cc/playground/Code/Time).
9+
**MCP79412RTC** is an Arduino library that supports the Microchip MCP7941x Real-Time Clock/Calendar chips. It is intended to be used with the [Arduino Time library] (http://www.arduino.cc/playground/Code/Time).
1010

11-
The **MCP79412RTC** library is a drop-in replacement for the **DS1307RTC** library by Michael Margolis that is supplied with the [Arduino Time library](http://www.arduino.cc/playground/Code/Time). To change from using a DS1307 RTC to an MCP79412 RTC, it is only necessary to use `#include <MCP79412RTC.h>` instead of `#include <DS1307RTC.h>`.
11+
The **MCP79412RTC** library is a drop-in replacement for the **DS1307RTC** library by Michael Margolis that is supplied with the [Arduino Time library](http://www.arduino.cc/playground/Code/Time). To change from using a DS1307 RTC to an MCP7941x RTC, it is only necessary to use `#include <MCP79412RTC.h>` instead of `#include <DS1307RTC.h>`.
1212

13-
The **MCP79412RTC** library also implements methods to support the additional features of the MCP79412 RTC.
13+
The **MCP79412RTC** library also implements methods to support the additional features of the MCP7941x RTC.
1414

1515
**For more information on the MCP79412, see:**
1616
[My Blog Post](http://goo.gl/MkBnjR), summarizing the features and advantages of the MCP79412
1717
[My Power Outage Logger Project](http://goo.gl/RfM5os), an Arduino-based project featuring the MCP79412
1818
The [Microchip MCP79412 Product Page](http://goo.gl/SHfKe0) for specs, datasheet, etc.
19-
MCP79412 breakout boards are available at [my Tindie Store](http://goo.gl/UzAVcZ)
19+
MCP79411 and MCP79412 breakout boards are available at [my Tindie Store](http://goo.gl/UzAVcZ)
2020

2121
## Installation ##
2222
To use the **MCP79412RTC** library:
@@ -463,3 +463,19 @@ No function value returned. The RTC's ID is returned to the **uniqueID** array.
463463
byte buf[8];
464464
RTC.idRead(buf);
465465
```
466+
--------------------------------------------------------------------------------
467+
468+
###getEUI64(byte *uniqueID)
469+
#####Description
470+
Returns an EUI-64 ID. For an MCP79412, calling this function is equivalent to calling `idRead()`. For an MCP79411, the EUI-48 ID is converted to EUI-64. Caller must provide an 8-byte array to contain the results.
471+
#####Syntax
472+
`RTC.getEUI64(byte *uniqueID);`
473+
#####Parameters
474+
**uniqueID:** An 8-byte array to receive the EUI-64 unique ID _(*byte)_
475+
#####Returns
476+
No function value returned. The EUI-64 ID is returned to the **uniqueID** array.
477+
#####Example
478+
```c++
479+
byte buf[8];
480+
RTC.getEUI64(buf);
481+
```

0 commit comments

Comments
 (0)