eldruin / eeprom24x-rs

Platform agnostic Rust driver for 24x series serial EEPROM devices using embedded-hal

Home Page:https://blog.eldruin.com/24x-serial-eeprom-driver-in-rust/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple I2C devices on same bus

chevdor opened this issue · comments

Hello, how is it planned to access multiple eeproms on the same I2C bus?

Consider the following code:

let mut eeprom1 = Eeprom24x::new_24x32(i2c2, SlaveAddr::Alternative(false, false, false));
let mut eeprom2 = Eeprom24x::new_24x32(i2c2, SlaveAddr::Alternative(true, false, false));

Each line is valid and the code (write / read) works fine. However, since eeprom1 takes ownership of i2c2, it is then no longer usable for eeprom2. Shouln't you avoid taking ownership of the bus ?

Hello @chevdor, you can use shared-bus to share a bus among several devices.

Thank you for sharing @eldruin.
I see that taking ownership is common practise and refcell may also be an option. I did not know about shared-bus, thanks for sharing that one. I am closing this issue then and I will test those options.