| Crates.io | cat24c32-rs |
| lib.rs | cat24c32-rs |
| version | 0.1.0 |
| created_at | 2025-08-14 13:05:53.51902+00 |
| updated_at | 2025-08-14 13:05:53.51902+00 |
| description | Platform-agnostic Rust driver for CAT24C32 EEPROM Serial 32Kb I2C devices |
| homepage | https://github.com/PixmaNts/cat24c32-rs |
| repository | https://github.com/PixmaNts/cat24c32-rs |
| max_upload_size | |
| id | 1794851 |
| size | 59,190 |
Platform-agnostic Rust driver for the CAT24C32 EEPROM Serial 32-Kb I2C device using the embedded-hal traits.
The CAT24C32 is an EEPROM Serial 32-Kb I2C device, internally organized as 4096 words of 8 bits each. It features a 32-byte page write buffer and supports the Standard (100 kHz), Fast (400 kHz) and Fast-Plus (1 MHz) I2C protocol. External address pins make it possible to address up to eight CAT24C32 devices on the same bus.
Datasheet: CAT24C32
Add this to your Cargo.toml:
[dependencies]
cat24c32-rs = "0.1.0"
embedded-hal = "1.0.0"
To use this driver, import this crate and an embedded_hal implementation, then instantiate the device:
use cat24c32_rs::{Cat24c32, SlaveAddr};
use linux_embedded_hal::I2cdev;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let dev = I2cdev::new("/dev/i2c-1")?;
let mut eeprom = Cat24c32::new(dev, SlaveAddr::Default);
// Write a byte
eeprom.write_byte(0x00, 0x42)?;
// Read a byte
let value = eeprom.read_byte(0x00)?;
println!("Read value: 0x{:02X}", value);
// Write a page (up to 32 bytes)
let data = [0xAA; 32];
eeprom.write_page(0x00, &data)?;
// Read multiple bytes
let mut buffer = [0u8; 32];
eeprom.read_data(0x00, &mut buffer)?;
println!("Read data: {:?}", buffer);
Ok(())
}
The driver also implements the embedded-storage traits for ecosystem compatibility:
use cat24c32_rs::Cat24c32;
use embedded_storage::{ReadStorage, Storage};
use embedded_storage::nor_flash::NorFlash;
fn storage_example() -> Result<(), Box<dyn std::error::Error>> {
let dev = I2cdev::new("/dev/i2c-1")?;
let mut eeprom = Cat24c32::new(dev, SlaveAddr::Default);
// Using ReadStorage trait
let mut buffer = [0u8; 64];
ReadStorage::read(&mut eeprom, 0x0000, &mut buffer)?;
// Using NorFlash trait (automatic page write optimization)
let data = b"Hello, embedded-storage!";
NorFlash::write(&mut eeprom, 0x0100, data)?;
// Check capacity
assert_eq!(ReadStorage::capacity(&eeprom), 4096); // 4KB
Ok(())
}
For questions, issues, feature requests, and other changes, please file an issue in the github project.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.