#front-end #driver #analog #no-std-driver #spi-driver #ultrasonic #sensing

no-std tdc1000

TDC1000超声波传感模拟前端no_std驱动程序

2个版本

0.1.2 2022年2月11日
0.1.1 2021年7月27日
0.1.0 2021年7月27日

#665 in 嵌入式开发

MIT/Apache

35KB
1K SLoC

build_workflow Crates.io Version Crates.io Downloads No Std

TDC1000

这个crate是一个TDC1000超声波传感模拟前端no_std驱动程序

数据表

https://www.ti.com/lit/gpn/tdc1000

关于此驱动程序

此驱动程序允许您通过spi配置tdc1000模拟前端设备。此驱动程序在编译为发布模式时在NUCLEO-L433RC上运行。

使用方法

将此添加到您的Cargo.toml

[dependencies]
tdc1000 = "0.1.2"

并将此添加到您的main.rs

//SPI
    let sck = gpioa.pa5.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
    let miso = gpioa.pa6.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
    let mosi = gpioa.pa7.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
    let mut cs = gpioa
        .pa4
        .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
    cs.set_high().unwrap();

    //TDC 1000 enable
    let mut enable_pin = gpioc
        .pc8
        .into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper);
        enable_pin.set_low().unwrap();

    //TDC 1000 trigger
    let mut trigger_pin = gpioc
    .pc9
    .into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper);
    trigger_pin.set_low().unwrap();

    //TDC 1000 start pulse pin
    let start_pin = gpioc
    .pc7
    .into_pull_down_input(&mut gpioc.moder, &mut gpioc.pupdr);

    //TDC 1000 stop pulse pin
    let stop_pin = gpioc
    .pc6
    .into_pull_down_input(&mut gpioc.moder, &mut gpioc.pupdr);

    let mut tdc1000 = Tdc1000::default();
    tdc1000.set_tx_frequency_divider(TxFrequencyDivider::DivideBy8);
    tdc1000.set_number_of_tx_pulses(TxPulses::new(1)); 
    tdc1000.set_tx_pulse_shift_position(TxPulseShiftPosition::new(5));
    tdc1000.set_time_of_flight(TimeOfFlightValue::new(TimeOfFlightValue::HIGH));
    tdc1000.set_short_tof_blank_period(ShortTofBlankPeriod::T0Times32);
    tdc1000.write_settings(&mut cs, &mut spi).unwrap();
    

    loop {
        enable_pin.set_high().unwrap();
        delay_ms(10_u32);
        let mut timeout = 0_u32;
        while start_pin.is_low().unwrap() && timeout < SOME_TIMEOUT {
            timeout += 1;
        }
        let start_cnt = DWT::get_cycle_count(); // Use cycle count to measure time

        timeout = 0;
        while stop_pin.is_low().unwrap() && timeout < SOME_TIMEOUT {
            timeout += 1;
        }
        let stop_ctn = DWT::get_cycle_count();

        let measured_cycles = stop_cnt - start_cnt; 
        
        enable_pin.set_high().unwrap();
        delay_ms(5000_u32);
    }

许可证

根据您的要求,许可如下:

依赖

~71KB