Remarks

AT24Cxx
Status
Source code GitHub
NuGet package

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.

Purchasing

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    At24Cxx eeprom;

    public MeadowApp()
    {
        //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);

        Console.WriteLine("Write to eeprom");

        eeprom.Write(0, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

        Console.WriteLine("Read from eeprom");

        var memory = eeprom.Read(0, 16);

        for (ushort index = 0; index < 16; index++)
        {
            Thread.Sleep(50);
            Console.WriteLine("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);
            Console.WriteLine("Byte: " + index + ", Value: " + memory[index]);
        }
    }
}

Sample projects available on GitHub

Wiring Example

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

At24Cxx Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object > At24Cxx
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.ICs.EEPROM
Assembly AT24Cxx.dll

Syntax

public class At24Cxx

Constructors

At24Cxx(II2cBus, Byte, UInt16, UInt16)

Create a new AT24Cxx object using the default parameters for the component.

Declaration
public At24Cxx(II2cBus i2cBus, byte address = 80, ushort pageSize = 32, ushort memorySize = 8192)

Parameters

Type Name Description
II2cBus i2cBus
System.Byte address

Address of the At24Cxx (default = 0x50).

System.UInt16 pageSize

Number of bytes in a page (default = 32 - AT24C32).

System.UInt16 memorySize

Total number of bytes in the EEPROM (default = 8192 - AT24C32).

Methods

Read(UInt16, UInt16)

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

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

Parameters

Type Name Description
System.UInt16 startAddress

Start address for the read operation.

System.UInt16 amount

Amount of data to read from the EEPROM.

Returns

Type Description
System.Byte[]

Write(UInt16, Byte[])

Write a number of bytes to the EEPROM.

Declaration
public void Write(ushort startAddress, byte[] data)

Parameters

Type Name Description
System.UInt16 startAddress

Address of he first byte to be written.

System.Byte[] data

Data to be written to the EEPROM.