lis3mdl
A platform agnostic driver to interface with the LIS3MDL (3-axis magnetic sensor).
Using the B-L475E-IOT01A1 board and the stm32l4xx_hal
crate.
```rust // 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.intoopendrainoutput(&mut gpiob.moder, &mut gpiob.otyper); scl.internalpullup(&mut gpiob.pupdr, true); let scl = scl.intoaf4(&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.intoopendrainoutput(&mut gpiob.moder, &mut gpiob.otyper); sda.internalpullup(&mut gpiob.pupdr, true); let sda = sda.intoaf4(&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 = lis3mdldevice.getmagaxesmgauss().unwrap(); ```
Licensed under either of
at your option.
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.