[][src]Module stm32l0x1_hal::i2c

Inter-Integrated Circuit (I2C) bus

This is a master-mode-only implementation of I2C.

Take care to note that the write and write_read methods accept an address argument that is not shifted on your behalf.

use stm32l0x1_hal;

let d = stm32l0x1_hal::stm32l0x1::Peripherals::take().unwrap();
let i2c = d.I2C;
let mut flash = d.FLASH.constrain();
let mut pwr = d.PWR.constrain();
let mut rcc = d.RCC.constrain().freeze(&mut flash, &mut pwr);

let gpiob = gpio::B::new(d.GPIOB, &mut self.rcc.iop);

let i2c_sda = gpiob.PB7.into_output::<OpenDrain, PullUp>().into_alt_fun::<AF1>();
i2c_sda.set_pin_speed(PinSpeed::VeryHigh);

let i2c_scl = gpiob.PB6.into_output::<OpenDrain, PullUp>().into_alt_fun::<AF1>();
i2c_scl.set_pin_speed(PinSpeed::VeryHigh);

let i2c_addr = 0x32 << 1; // <-- !!! you must shift your address accordingly

let mut i2c = i2c::I2c::i2c1(
    i2c1,
    (i2c_scl, i2c_sda),
    i2c::I2cClkSrc::HSI16,
    0x00303D5B, // timing_reg
    &mut rcc.apb1,
    &mut rcc.ccipr,
);

i2c.write(i2c_addr, &[0x00, (0x1 << 6) as u8]).unwrap();
let result = i2c.write_read(i2c_addr, &[0x01]).unwrap();

Structs

I2c

I2C peripheral operating in master mode

Enums

Error

I2C error

I2cClkSrc

Available clock sources for I2C modules