Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 10 additions & 9 deletions examples/i2c-bme280/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, I2cExt, Mode},
pac,
prelude::*,
rcc,
Expand Down Expand Up @@ -54,33 +54,34 @@ 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;

let i2c = dp
.I2C1
//.remap(&mut afio.mapr) // add this if want to use PB8, PB9 instead
.blocking_i2c(
(scl, sda),
Mode::Fast {
.i2c((scl, sda),
Mode::Fast {
frequency: 400.kHz(),
duty_cycle: DutyCycle::Ratio16to9,
},
&clocks,
}
, &mut rcc)
.blocking(
1000,
10,
1000,
1000,
&rcc.clocks
);

// 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| {
Expand Down
4 changes: 4 additions & 0 deletions src/i2c/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ impl<I2C: Instance> BlockingI2c<I2C> {
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)?;
Expand Down