MCP79410RK
Public Member Functions
MCP79410EEPROM Class Reference

Class for accessing the MCP79410 EEPROM. More...

#include <MCP79410RK.h>

Inheritance diagram for MCP79410EEPROM:
MCP79410MemoryBase

Public Member Functions

 MCP79410EEPROM (MCP79410 *parent)
 Class to read and write the 64-byte SRAM (battery backed RAM) block in the MCP79410. More...
 
virtual ~MCP79410EEPROM ()
 Destructor. Not normally used as MCP79410 constructs this object and the MCP79410 is typically a global object.
 
uint8_t getBlockProtection () const
 Get the EEPROM block protection register. More...
 
bool setBlockProtection (uint8_t value)
 Sets the block protection. More...
 
bool protectedBlockRead (uint8_t *buf)
 Read from the 8-byte protected block in EEPROM. More...
 
virtual size_t length () const
 Returns the length (128)
 
virtual uint8_t eraseValue () const
 Erased value is 0xff.
 
virtual bool readData (size_t addr, uint8_t *data, size_t dataLen)
 Low-level API to read data from memory. More...
 
virtual bool writeData (size_t addr, const uint8_t *data, size_t dataLen)
 Low-level API to write data to memory. More...
 
- Public Member Functions inherited from MCP79410MemoryBase
 MCP79410MemoryBase (MCP79410 *parent)
 Constructor.
 
virtual ~MCP79410MemoryBase ()
 Destructor.
 
virtual bool erase ()
 Erase the memory. More...
 
template<typename T >
T & get (size_t addr, T &t)
 Templated accessor to get data from a specific offset. This API works like the EEPROM API. More...
 
template<typename T >
const T & put (size_t addr, const T &t)
 Templated accessor to set data at a specific offset. This API works like the EEPROM API. More...
 

Additional Inherited Members

- Protected Attributes inherited from MCP79410MemoryBase
MCP79410parent
 The MCP79410 object that this object is associated with.
 

Detailed Description

Class for accessing the MCP79410 EEPROM.

The EEPROM is non-volatile, and values persist even when both the power and backup battery are removed. It is slow to write to and has a finite number of write cycles.

You do not instantiate one of these, use the rtc.eeprom() method to get a reference to this object.

The default from the factory is 0xff bytes in all locations.

While you can use readData() and writeData(), you can also use the get() and put() methods like the EEPROM API to read and write primitives (int, bool, etc.) as well as structures. Note that you cannot get and put a String or char *, however, you can only store an array of characters.

Constructor & Destructor Documentation

◆ MCP79410EEPROM()

MCP79410EEPROM::MCP79410EEPROM ( MCP79410 parent)

Class to read and write the 64-byte SRAM (battery backed RAM) block in the MCP79410.

You should never construct one of these; the object is exposed by the MCP79410 class.

Member Function Documentation

◆ getBlockProtection()

uint8_t MCP79410EEPROM::getBlockProtection ( ) const

Get the EEPROM block protection register.

Constant Value Description
MCP79410::EEPROM_PROTECT_NONE 0x0; Able to write all bytes
MCP79410::EEPROM_PROTECT_UPPER_QUARTER 0x1 0x60 - 0x7f protected from writing
MCP79410::EEPROM_PROTECT_UPPER_HALF 0x2 0x40 - 0x7f protected from writing
MCP79410::EEPROM_PROTECT_ALL 0x3 All bytes protected from writing

The default value from the factory is 0 (EEPROM_PROTECT_NONE).

Setting it to other values will cause writes to the protected sections to not actually write until you change the protection register to allow writes again.

Note: block protection is separate from the 8-byte protected block, which is confusing.

◆ protectedBlockRead()

bool MCP79410EEPROM::protectedBlockRead ( uint8_t *  buf)

Read from the 8-byte protected block in EEPROM.

Parameters
bufA pointer to an 8-byte buffer to hold the data.

The constant MCP79410::EEPROM_PROTECTED_BLOCK_SIZE can be used instead of 8.

This is different from the block protection (getBlockProtection() and setBlockProtection(). This protected block can only be written to using a special technique. See MCP79410::eepromProtectedBlockWrite.

This block is normally used for things like MAC addresses, board identification codes, etc. that are programmed once at the factory and never reset in the field.

The default from the factory is 0xff bytes for all 8 bytes.

◆ readData()

bool MCP79410EEPROM::readData ( size_t  addr,
uint8_t *  data,
size_t  dataLen 
)
virtual

Low-level API to read data from memory.

Parameters
addrAddress in the memory block (0 = beginning of block; do not use hardware register address)
dataPointer to buffer to store data in
dataLenNumber of bytes to read

Implements MCP79410MemoryBase.

◆ setBlockProtection()

bool MCP79410EEPROM::setBlockProtection ( uint8_t  value)

Sets the block protection.

Parameters
valueThe value, such as MCP79410::EEPROM_PROTECT_NONE. See getBlockProtection() for more details.

◆ writeData()

bool MCP79410EEPROM::writeData ( size_t  addr,
const uint8_t *  data,
size_t  dataLen 
)
virtual

Low-level API to write data to memory.

Parameters
addrAddress in the memory block (0 = beginning of block; do not use hardware register address)
dataPointer to buffer containing the data to write to memory. Buffer is not modified (is const).
dataLenNumber of bytes to write

Implements MCP79410MemoryBase.


The documentation for this class was generated from the following files: