MCP794xx Battery-Backed I2C Real-Time Clock/Calendar with SRAM, (optional) EEPROM and Protected EEPROM

This is a module that makes it easy to connect to a MCP794xx I2C real time clock / calendar.

The MCP794xx is a family of I2C real time clocks from Microchip with 64 byte battery backed SRAM and Protected EEPROM. The MCP7941x parts also contain 128 byte EEPROM. This module makes it easy to connect this clock with an espruino board.

Use the MCP794xx module for it.

Wiring Up

Pin Espruino
VCC 3.3v
MFP Not implemented


How to use the module:

I2C1.setup({scl:A5,sda:A4, bitrate: 60000});
var rtc = require('MCP794xx').connect(I2C1);

// you have to enable vbat on first use. It's not on by default, won't keep time from the backup battery...

// set the date - assuming the "Set Current Time" is set in your Espruino IDE, just uploading this code will set it up
rtc.setDateTime(new Date()) 

// get the date & time from the RTC, for example at boot
var now = rtc.getDateTime()
// and set Espruino's internal clock to it

Using SRAM

All MCP794xx parts have 64 byte battery backed SRAM. Store anything you want to keep as long as the RTC has battery. The battery backed SRAM area starts at 0x20.

// pass in the memory address, and data in a regular array, or Uint8Array
rtc.sramWrite(0x20, [42, 42, 42, 42])

// read back data
rtc.sramRead(0x20, 4)
// =new Uint8Array([42, 42, 42, 42])


The MCP7941x parts contain 128 bytes of EEPROM - store anything you want :) The EEPROM address starts at 0. This library handles EEPROM memory "paging", so you can send in more than 8 bytes of data easily.

// first parameter is the memory address
rtc.eepromWrite(0, [1,2,3,4,5,6,7])

// first parameter is the memory address, second is the number of bytes to read
// =new Uint8Array([1, 2, 3, 4, 5, 6])

EUI-48 / EUI-64 in MCP794x1 and MCP794x2

The MCP794x1 parts have an EUI-48, the MCP794x2 have an EUI-64 node address factory programmed. You can use these as a unique identifiers of the device.

/// Reads the factory programmed 48 bit EUI. Only for MCP794x1

// or 

/// Reads the factory programmed 64 bit EUI. Only for MCP794x2

Other features

Alerts, using the MFP pin and some other things not implemented. Send a PR or raise an issue, if you need something else :)


MCP794xx.prototype.constructor = function (i2c) { ... }

MCP794xx.prototype._rd = function (reg, cnt) { ... }

MCP794xx.prototype._wr = function (reg, data) { ... }

// read from the "eeprom" address of the MCP
MCP794xx.prototype._eRd = function (reg, cnt) { ... }

// write to the "eeprom" address of the MCP
MCP794xx.prototype._eWr = function (reg, data) { ... }

// reads current date&time and returns it as a Date object
MCP794xx.prototype.getDateTime = function () { ... }

// Sets the date from the given Date object
MCP794xx.prototype.setDateTime = function (d) { ... }

MCP794xx.prototype.enableVbat = function () { ... }

// Reads the factory programmed 48 bit EUI. Only for MCP794x1
MCP794xx.prototype.readEUI48 = function () { ... }

// Reads the factory programmed 64 bit EUI. Only for MCP794x2
MCP794xx.prototype.readEUI64 = function () { ... }

// Read bytes from the battery backed SRAM
MCP794xx.prototype.sramRead = function (startAddress, numBytes) { ... }

// Writes bytes to the battery backed SRAM
MCP794xx.prototype.sramWrite = function (startAddress, data) { ... }

// Reads data from the EEPROM
MCP794xx.prototype.eepromRead = function (startAddress, numBytes) { ... }

// Writes data to the EEPROM. Handles paging, you can give as much data, as much data as you want
MCP794xx.prototype.eepromWrite = function (startAddress, data) { ... }

exports.connect = function (i2c) { ... }

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.