Hello
Im trying Rust language with my HiFive1 rev b board.
Im using led_gpio example from here, there is no example how to read data from pin and basing on IDE hints im trying to read input on pin from DHT22 sensor.
Here is code:
#![no_std]
#![no_main]
/*
* Basic blinking external LED using GPIO pin example.
* WARNING: requires a LED to be wired to physical PIN9 with at least
* a 320 Ohm resistor in series similar to
* https://create.arduino.cc/projecthub/rowan07/make-a-simple-led-circuit-ce8308
*/
extern crate panic_halt;
use hifive1::hal::delay::Sleep;
use hifive1::hal::prelude::*;
use hifive1::hal::DeviceResources;
use hifive1::{pin, sprintln};
use riscv_rt::entry;
#[entry]
fn main() -> ! {
let dr = DeviceResources::take().unwrap();
let p = dr.peripherals;
let pins = dr.pins;
// let pins = dr.pins;
// Configure clocks
let clocks = hifive1::clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
let mut eled = pin!(pins, dig9).into_output();
// GPIO PIN1 -> DIG9 physical on board (both hifive1 and hifive1-revB)
hifive1::stdout::configure(
p.UART0,
pin!(pins, uart0_tx),
pin!(pins, uart0_rx),
115_200.bps(),
clocks,
);
// get the local interrupts struct
let clint = dr.core_peripherals.clint;
// get the sleep struct
let mut sleep = Sleep::new(clint.mtimecmp, clocks);
const PERIOD: u32 = 1000; // 1s
sprintln!("loop");
loop {
eled.set_low().unwrap();
sleep.delay_ms(20);
eled.set_high().unwrap();
sleep.delay_ms(35);
sprintln!("sent");
let dr = DeviceResources::take().unwrap();
let pins = dr.pins;
let mut eled = pin!(pins, dig9).into_floating_input();
sprintln!("recive");
let recive = eled.is_high().unwrap();
sprintln!("{}", recive);
// // sleep for 1s
sleep.delay_ms(PERIOD);
}
}
Problem is it looks like it stuck after "sent" output to console and i have no idea why it is happening.
If i understand correctly those is_high/is_low methods i need to read status with one of it on pin with some IF condition and basing on it create input in some binary variable? How to properly read pin status, for now not all sent sequence but how to make just one proper check?
EDIT:
I made some additional tests and im reading pin status properly so problem will be when swapping pin configuration from output to input. How to make it properly in loop in Rust?