Skip to content

EepromAt24c32 object

Michael Miller edited this page Feb 25, 2019 · 3 revisions

EepromAt24c32 object provides access to all the functions of the At24cXX eeprom chip often found on a DS3231 module.

Constructors

template<class T_WIRE_METHOD> EepromAt24c32(T_WIRE_METHOD& wire, uint8_t addressBits)

Construct a eeprom object using the provided WIRE method and address bits configuration
T_WIRE_METHOD - the typename of the class to use for the wire method. TwoWire is the normal hardware method class.
wire - the instance of the T_WIRE_METHOD to use. Wire is the normal hardware instance to use.
addressBits - the configuration of address bits shorted together on the board. By default just leave this off. If you have shorted the pads together to change the address of the eeprom, then provide this value. The order of the bits is A2, A1, A0. By default this value is 0b111 and it is expected that none of the address pads are shorted. If A0 is shorted together on the board, then this value should be 0b110.
Below is an example of how to create an instance of the object using the normal Arduino hardware Wire support.

#include <Wire.h> 
#include <EepromAT24C32.h>

EepromAt24c32<TwoWire> RtcEeprom(Wire);

If you want to use SoftwareWire library, you can replace the above with this and it will work.

#include <SoftwareWire.h> 
#include <EepromAT24C32.h>

SoftwareWire myWire(SDA, SCL); // replace with the pins you use
EepromAt24c32<SoftwareWire> RtcEeprom(myWire);

Methods

void Begin()

The normal begin method that should be called within Setup()

uint8_t LastError()

<return>, the error code from the last Wire transaction. After each method call below, you may check if this return value for an error. See https://www.arduino.cc/en/Reference/WireEndTransmission for values of this error.

void SetMemory(uint16_t memoryAddress, uint8_t value)

memoryAddress - the address within the memory of the eeprom to store a value.
value - the 8 bit value to store.

uint8_t GetMemory(uint16_t memoryAddress)

memoryAddress - the address within the memory of the eeprom to retrieve a value.
<return>, the value of that memory address

uint8_t SetMemory(uint16_t memoryAddress, const uint8_t* pValue, uint8_t countBytes)

This method will write within a single page of eeprom. Pages are 32 bytes (5 bits), so writing past a page boundary will just wrap within the page of the starting memory address.
xxxppppp pppaaaaa => p = page #, a = address within the page

memoryAddress - the starting address within the memory of the eeprom to copy the following buffer
pValue - the pointer to a buffer of bytes
countBytes - the number of bytes to copy
<return>, the number of bytes actually copied. This maybe smaller than countBytes due to reaching the end of the available memory address page.

uint8_t GetMemory(uint16_t memoryAddress, uint8_t* pValue, uint8_t countBytes)

memoryAddress - the starting address within the memory of the eeprom to copy from
pValue - the pointer to a buffer of bytes to copy into
countBytes - the number of bytes to copy
<return>, the number of bytes actually copied. This maybe smaller than countBytes due to reaching the end of the available memory.

You can’t perform that action at this time.