Skip to content

Instantly share code, notes, and snippets.

@ntr-808
Created February 17, 2020 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntr-808/05c3a0a8678afee64684c3ddd7d19eb8 to your computer and use it in GitHub Desktop.
Save ntr-808/05c3a0a8678afee64684c3ddd7d19eb8 to your computer and use it in GitHub Desktop.
#![no_std]
#![no_main]
extern crate panic_semihosting;
use cortex_m_rt::entry;
use cortex_m_semihosting::{hprintln};
use f411::{
hal::{prelude::*, stm32, i2c::I2c},
Lsm303dlhc,
};
#[entry]
fn main() -> ! {
let p = stm32::Peripherals::take().unwrap();
// let mut flash = p.FLASH.constrain();
let rcc = p.RCC.constrain();
let clocks = rcc.cfgr.freeze();
let gpiob = p.GPIOB.split();
let scl = gpiob.pb6.into_alternate_af4();
let sda = gpiob.pb9.into_alternate_af4();
let i2c = I2c::i2c1(p.I2C1, (scl, sda), 400.khz(), clocks);
let mut lsm303dlhc = Lsm303dlhc::new(i2c).unwrap();
// never called
hprintln!("initialised lsm303dlhc").unwrap();
let accel = lsm303dlhc.accel().unwrap();
let mag = lsm303dlhc.mag().unwrap();
let temp = lsm303dlhc.temp().unwrap();
hprintln!("accel={:?}", accel).unwrap();
hprintln!("mac={:?}", mag).unwrap();
hprintln!("temp={:?}", temp).unwrap();
loop {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment