Skip to main content

Meadow.Foundation.ICs.EEPROM.At24Cxx

At24Cxx
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.ICs.EEPROM.At24Cxx

The AT24Cxx series of chips provide a mechanism for storing data that will survive a power outage or battery failure. These EEPROMs are available in varying sizes and are accessible using the I2C interface.

Code Example

At24Cxx eeprom;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

//256kbit = 256*1024 bits = 262144 bits = 262144 / 8 bytes = 32768 bytes
//if you're using the ZS-042 board, it has an AT24C32 and uses the default value of 8192
eeprom = new At24Cxx(i2cBus: Device.CreateI2cBus(), memorySize: 32768);

return base.Initialize();
}

public override Task Run()
{
Resolver.Log.Info("Write to eeprom");
eeprom.Write(0, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

Resolver.Log.Info("Read from eeprom");
var memory = eeprom.Read(0, 16);

for (ushort index = 0; index < 16; index++)
{
Thread.Sleep(50);
Resolver.Log.Info("Byte: " + index + ", Value: " + memory[index]);
}

eeprom.Write(3, new byte[] { 10 });
eeprom.Write(7, new byte[] { 1, 2, 3, 4 });
memory = eeprom.Read(0, 16);

for (ushort index = 0; index < 16; index++)
{
Thread.Sleep(50);
Resolver.Log.Info("Byte: " + index + ", Value: " + memory[index]);
}

return base.Run();
}

Sample project(s) available on GitHub

Wiring Example

To wire a At24Cxx to your Meadow board, connect the following:

At24CxxMeadow Pin
GNDGND
SCLD08 (SCL)
SDAD07 (SDA)
VCC3V3

It should look like the following diagram:

Class At24Cxx

Encapsulation for EEPROMs based upon the AT24Cxx family of chips

Assembly: At24Cxx.dll
View Source
Declaration
public class At24Cxx : II2cPeripheral

Implements:
Meadow.Hardware.II2cPeripheral

Properties

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

PageSize

Number of bytes in a page

View Source
Declaration
public ushort PageSize { get; }

MemorySize

Number of bytes in the EEPROM module

View Source
Declaration
public ushort MemorySize { get; }

Fields

i2cComms

I2C Communication bus used to communicate with the peripheral

View Source
Declaration
protected readonly II2cCommunications i2cComms

Methods

Read(ushort, ushort)

Force the sensor to make a reading and update the relevant properties.

View Source
Declaration
public byte[] Read(ushort startAddress, ushort amount)
Returns

System.Byte[]

Parameters
TypeNameDescription
System.UInt16startAddressStart address for the read operation.
System.UInt16amountAmount of data to read from the EEPROM.

Write(ushort, params byte[])

Write a number of bytes to the EEPROM.

View Source
Declaration
public void Write(ushort startAddress, params byte[] data)
Parameters
TypeNameDescription
System.UInt16startAddressAddress of he first byte to be written.
System.Byte[]dataData to be written to the EEPROM.

Implements

  • Meadow.Hardware.II2cPeripheral