Struct avr_hal_generic::i2c::I2c
source · pub struct I2c<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> { /* private fields */ }
Expand description
I2C driver
§Example
(for Arduino Uno)
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut i2c = arduino_hal::I2c::new(
dp.TWI,
pins.a4.into_pull_up_input(),
pins.a5.into_pull_up_input(),
50000,
);
// i2c implements the embedded-hal traits so it can be used with generic drivers.
Implementations§
source§impl<H, I2C, SDAPIN, SCLPIN, CLOCK> I2c<H, I2C, Pin<Input, SDAPIN>, Pin<Input, SCLPIN>, CLOCK>
impl<H, I2C, SDAPIN, SCLPIN, CLOCK> I2c<H, I2C, Pin<Input, SDAPIN>, Pin<Input, SCLPIN>, CLOCK>
sourcepub fn new(
p: I2C,
sda: Pin<Input<PullUp>, SDAPIN>,
scl: Pin<Input<PullUp>, SCLPIN>,
speed: u32
) -> Self
pub fn new( p: I2C, sda: Pin<Input<PullUp>, SDAPIN>, scl: Pin<Input<PullUp>, SCLPIN>, speed: u32 ) -> Self
Initialize an I2C peripheral on the given pins.
Note that the SDA and SCL pins are hardwired for each I2C peripheral and you must pass the correct ones. This is enforced at compile time.
This method expects the internal pull-ups to be configured for both pins to comply with the
I2C specification. If you have external pull-ups connected, use
I2c::with_external_pullup
instead.
sourcepub fn with_external_pullup(
p: I2C,
sda: Pin<Input<Floating>, SDAPIN>,
scl: Pin<Input<Floating>, SCLPIN>,
speed: u32
) -> Self
pub fn with_external_pullup( p: I2C, sda: Pin<Input<Floating>, SDAPIN>, scl: Pin<Input<Floating>, SCLPIN>, speed: u32 ) -> Self
Initialize an I2C peripheral on the given pins.
Note that the SDA and SCL pins are hardwired for each I2C peripheral and you must pass the correct ones. This is enforced at compile time.
This method expects that external resistors pull up SDA and SCL.
source§impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> I2c<H, I2C, SDA, SCL, CLOCK>
impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> I2c<H, I2C, SDA, SCL, CLOCK>
sourcepub fn ping_device(
&mut self,
address: u8,
direction: Direction
) -> Result<bool, Error>
pub fn ping_device( &mut self, address: u8, direction: Direction ) -> Result<bool, Error>
Test whether a device answers on a certain address.
sourcepub fn i2cdetect<W: uWrite>(
&mut self,
w: &mut W,
direction: Direction
) -> Result<(), W::Error>
pub fn i2cdetect<W: uWrite>( &mut self, w: &mut W, direction: Direction ) -> Result<(), W::Error>
Scan the bus for connected devices. This method will output an summary in the format known
from i2cdetect(8)
on the selected serial connection. For example:
- 0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- 38 39 -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --