Remarks
At24Cxx | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | 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
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:
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 |
Namespace | Meadow.Foundation.ICs.EEPROM |
Assembly | At24Cxx.dll |
Syntax
public class At24Cxx : object
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 = null, ushort pageSize = null, ushort memorySize = null)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | I2CBus connected to display |
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). |
Properties
MemorySize
Number of bytes in the EEPROM module.
Declaration
public ushort MemorySize { get; }
Property Value
Type | Description |
---|---|
System.UInt16 |
PageSize
Number of bytes in a page.
Declaration
public ushort PageSize { get; }
Property Value
Type | Description |
---|---|
System.UInt16 |
Methods
Read(UInt16, UInt16)
Force the sensor to make a reading and update the relevant 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, params 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. |