lis3mdl-driver

Crates.iolis3mdl-driver
lib.rslis3mdl-driver
version0.1.0
sourcesrc
created_at2021-11-16 01:59:51.119814
updated_at2021-11-16 01:59:51.119814
descriptionA platform agnostic driver to interface with the LIS3MDL (3-axis magnetic sensor)
homepage
repositoryhttps://github.com/nnarain/lis3mdl
max_upload_size
id482444
size35,325
Natesh Narain (nnarain)

documentation

README

lis3mdl

A platform agnostic driver to interface with the LIS3MDL (3-axis magnetic sensor).

Examples

Using the B-L475E-IOT01A1 board and the stm32l4xx_hal crate.

// Set up the L475 peripherals
let p = stm32l4xx_hal::stm32l4::stm32l4x5::Peripherals::take().unwrap();
let mut rcc = p.RCC.constrain();
let mut gpiob = p.GPIOB.split(&mut rcc.ahb2);

// Set up clock signal as open drain with internal pull up on PB10 in alternate mode 4
let mut scl = gpiob.pb10.into_open_drain_output(&mut gpiob.moder, &mut gpiob.otyper);
scl.internal_pull_up(&mut gpiob.pupdr, true);
let scl = scl.into_af4(&mut gpiob.moder, &mut gpiob.afrh);

// Set up the data signal as open drain with internal pull up on PB11 in alternate mode 4
let mut sda = gpiob.pb11.into_open_drain_output(&mut gpiob.moder, &mut gpiob.otyper);
sda.internal_pull_up(&mut gpiob.pupdr, true);
let sda = sda.into_af4(&mut gpiob.moder, &mut gpiob.afrh);

// Set up the I2C peripheral (using I2C2)
let i2c2 = I2c::i2c2(p.I2C2,(scl,sda),100.khz(),clocks,&mut rcc.apb1r1);

// Initialize the LIS3MDL with the I2C
let mut lis3mdl_device = Lis3mdl::new(i2c2).unwrap();

// Read the X, Y, and Z axes values in milliGauss
let xyz = lis3mdl_device.get_mag_axes_mgauss().unwrap();

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 7

cargo fmt