#embedded #onewire #embedded-hal-driver #1wire #stm32

no-std onewire

OneWire implementation using embedded_hal as abstraction layer, based on arduino OneWire library. WIP

20 releases

✓ Uses Rust 2018 edition

0.3.13 Oct 15, 2019
0.3.10 Feb 23, 2019
0.3.9 Jul 16, 2018
0.3.5 Mar 18, 2018

#67 in #stm32

Download history 343/week @ 2019-12-08 1/week @ 2019-12-15 21/week @ 2019-12-22 2/week @ 2019-12-29 4/week @ 2020-01-05 195/week @ 2020-01-12 43/week @ 2020-01-19 2/week @ 2020-01-26 1/week @ 2020-02-02 21/week @ 2020-02-09 21/week @ 2020-02-16 60/week @ 2020-02-23 41/week @ 2020-03-08 23/week @ 2020-03-15 83/week @ 2020-03-22

244 downloads per month

MIT/Apache

24KB
594 lines

How to use

Below is an example how to create a new OneWire instance, search for devices and read the temperature from a DS18B20. The example currently requires the stm32f103xx-hal to be patched with this PR.

fn main() -> ! {
    let mut cp: cortex_m::Peripherals = cortex_m::Peripherals::take().unwrap();
    let mut peripherals = stm32f103xx::Peripherals::take().unwrap();
    let mut flash = peripherals.FLASH.constrain();
    let clocks = rcc.cfgr.freeze(&mut flash.acr);
    let mut rcc = peripherals.RCC.constrain();
    let mut gpioc = peripherals.GPIOC.split(&mut rcc.apb2);
    
    let mut delay = stm32f103xx_hal::delay::Delay::new(cp.SYST, clocks);
    
    let mut one = gpioc
        .pc15
        .into_open_drain_output(&mut gpioc.crh)
        .downgrade();
        
    let mut wire = OneWire::new(&mut one, false);
    
    if wire.reset(&mut delay).is_err() {
        // missing pullup or error on line
        loop {}
    }
    
    // search for devices
    let mut search = DeviceSearch::new();
    while let Some(device) = wire.search_next(&mut search, &mut delay).unwrap() {
        match device.address[0] {
            ds18b20::FAMILY_CODE => {
                let mut ds18b20 = DS18b20::new(device).unwrap();
                
                // request sensor to measure temperature
                let resolution = ds18b20.measure_temperature(&mut wire, &mut delay).unwrap();
                
                // wait for compeltion, depends on resolution 
                delay.delay_ms(resolution.time_ms());
                
                // read temperature
                let temperature = ds18b20.read_temperature(&mut wire, &mut delay).unwrap();
            },
            _ => {
                // unknown device type            
            }
        }
    }
    
    loop {}
}

The code from the example is copy&pasted from a working project, but not tested in this specific combination.

Dependencies

~200KB