-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathmpu9250.rs
63 lines (45 loc) · 1.3 KB
/
mpu9250.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Interfacing the MPU9250
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_halt as _;
use cortex_m::asm;
use cortex_m_rt::entry;
use mpu9250::Mpu9250;
use stm32f1xx_hal as hal;
use hal::{pac, prelude::*, spi::Spi};
#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();
let mut flash = dp.FLASH.constrain();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut gpioa = dp.GPIOA.split();
// let mut gpiob = dp.GPIOB.split();
let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
// SPI1
let sck = gpioa.pa5;
let miso = gpioa.pa6;
let mosi = gpioa.pa7;
// SPI2
// let sck = gpiob.pb13;
// let miso = gpiob.pb14;
// let mosi = gpiob.pb15;
let spi = Spi::new(
dp.SPI1,
(Some(sck), Some(miso), Some(mosi)),
mpu9250::MODE.into(),
1.MHz(),
&clocks,
);
let mut delay = cp.SYST.delay(&clocks);
let mut mpu9250 = Mpu9250::marg_default(spi, nss, &mut delay).unwrap();
// sanity checks
assert_eq!(mpu9250.who_am_i().unwrap(), 0x71);
assert_eq!(mpu9250.ak8963_who_am_i().unwrap(), 0x48);
let _a = mpu9250.all::<[f32; 3]>().unwrap();
asm::bkpt();
loop {}
}