Crate eeprom24x[−][src]
This is a platform agnostic Rust driver for the 24x series serial EEPROM,
based on the embedded-hal
traits.
This driver allows you to:
- Read a single byte from a memory address:
read_byte
- Read a byte array starting on a memory address:
read_data
- Read the current memory address (please read notes):
read_current_address
- Write a byte to a memory address:
write_byte
- Write a byte array (up to a memory page) to a memory address:
write_page
Can be used at least with the devices AT24C32, AT24C64, AT24C128, AT24C256 and AT24C512.
The devices
These devices provides a number of bits of serial electrically erasable and programmable read only memory (EEPROM) organized as a number of words of 8 bits each. The devices' cascadable feature allows up to 8 devices to share a common 2-wire bus. The devices are optimized for use in many industrial and commercial applications where low power and low voltage operation are essential.
Device | Memory bits | 8-bit words | Page size | Datasheet |
---|---|---|---|---|
24x32 | 32,768 | 4096 | 32 bytes | AT24C32 |
24x64 | 65,536 | 8192 | 32 bytes | AT24C64 |
24x128 | 131,072 | 16,384 | 64 bytes | AT24C128 |
24x256 | 262,144 | 32,768 | 64 bytes | AT24C256 |
24x512 | 524,288 | 65,536 | 128 bytes | AT24C512 |
Usage examples (see also examples folder)
To create a new instance you can use the new_<device>
methods.
There are many compatible vendors so the method has a somewhat generic name.
For example, if you are using an AT24C32, you can create a device by calling
Eeprom24x::new_24x32(...)
.
Please refer to the device table above for more examples.
Instantiating with the default address
Import this crate and an embedded_hal
implementation, then instantiate
the device:
extern crate linux_embedded_hal as hal; extern crate eeprom24x; use hal::{I2cdev}; use eeprom24x::{Eeprom24x, SlaveAddr}; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let address = SlaveAddr::default(); // using the AT24C256 let mut eeprom = Eeprom24x::new_24x256(dev, address);
Providing an alternative address
extern crate linux_embedded_hal as hal; extern crate eeprom24x; use hal::{I2cdev}; use eeprom24x::{Eeprom24x, SlaveAddr}; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let (a2, a1, a0) = (false, false, true); let address = SlaveAddr::Alternative(a2, a1, a0); let mut eeprom = Eeprom24x::new_24x256(dev, address);
Writting and reading a byte
extern crate linux_embedded_hal as hal; extern crate eeprom24x; use hal::{I2cdev}; use eeprom24x::{Eeprom24x, SlaveAddr}; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let mut eeprom = Eeprom24x::new_24x256(dev, SlaveAddr::default()); let address = [0x12, 0x34]; let data = 0xAB; eeprom.write_byte(&address, data); // EEPROM enters internally-timed write cycle. Will not respond for some time. let retrieved_data = eeprom.read_byte(&address);
Writting a page
extern crate linux_embedded_hal as hal; extern crate eeprom24x; use hal::{I2cdev}; use eeprom24x::{Eeprom24x, SlaveAddr}; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let mut eeprom = Eeprom24x::new_24x256(dev, SlaveAddr::default()); let address = [0x12, 0x34]; let data = [0xAB; 64]; eeprom.write_page(&address, &data); // EEPROM enters internally-timed write cycle. Will not respond for some time.
Modules
ic |
Supported ICs (Integrated Circuits) |
Structs
Eeprom24x |
EEPROM24X driver |
Enums
Error |
All possible errors in this crate |
SlaveAddr |
Possible slave addresses |