diff --git a/CHANGELOG.md b/CHANGELOG.md index c6bb6dab..fe75bcbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- reset methods for I2C and BlockingI2C interfaces - `Serial` support for UART4/5 - Allow to set HSE bypass bit in `RCC` clock configuration register to use an external clock input on the `OSC_IN` pin [#485] - initial support of `embedded-hal-1.0` [#416] diff --git a/examples/i2c-bme280/src/main.rs b/examples/i2c-bme280/src/main.rs index 8bb91a9f..83b44307 100644 --- a/examples/i2c-bme280/src/main.rs +++ b/examples/i2c-bme280/src/main.rs @@ -24,7 +24,7 @@ use panic_semihosting as _; use bme280::i2c::BME280; use cortex_m_rt::entry; use stm32f1xx_hal::{ - i2c::{BlockingI2c, DutyCycle, Mode}, + i2c::{DutyCycle, Mode}, pac, prelude::*, rcc, @@ -54,10 +54,10 @@ fn main() -> ! { &mut flash.acr, ); - let mut afio = dp.AFIO.constrain(&mut rcc); + //let mut afio = dp.AFIO.constrain(&mut rcc); // add this if want to use PB8, PB9 instead // Acquire the GPIOB peripheral - let mut gpiob = dp.GPIOB.split(&mut rcc); + let gpiob = dp.GPIOB.split(&mut rcc); let scl = gpiob.pb6; let sda = gpiob.pb7; @@ -71,7 +71,7 @@ fn main() -> ! { frequency: 400.kHz(), duty_cycle: DutyCycle::Ratio16to9, }, - &clocks, + &mut rcc, 1000, 10, 1000, @@ -80,7 +80,7 @@ fn main() -> ! { // The Adafruit boards have address 0x77 without closing the jumper on the back, the BME280 lib connects to 0x77 with `new_secondary`, use // `new_primary` for 0x76 if you close the jumper/solder bridge. - let mut bme280 = BME280::new_secondary(i2c, cp.SYST.delay(&clocks)); + let mut bme280 = BME280::new_secondary(i2c, cp.SYST.delay(&rcc.clocks)); bme280 .init() .map_err(|error| { diff --git a/src/i2c/blocking.rs b/src/i2c/blocking.rs index 75ac9869..6cc25b9a 100644 --- a/src/i2c/blocking.rs +++ b/src/i2c/blocking.rs @@ -212,6 +212,10 @@ impl BlockingI2c { Ok(()) } + pub fn reset(&mut self) { + self.nb.reset(); + } + pub fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> { self.send_start_and_wait()?; self.send_addr_and_wait(addr, true)?;