Hello,
I'm just getting my feet wet in the embedded world. I've worked through most of the Embedded Discovery Book and now I'm trying to figure out how to use a DHT11 temperature/humidity sensor with the Discovery and I'm realizing that I'm almost completely lost lol. I've played with the examples in the stm32f3-discovery crate and also have successfully run the example code from the stm32f3xx_hal crate but I'm unsure how to connect this sensor to the board and then configure it properly so that I can read the data. I have the 3-pin version of the DHT11 so there is a VCC line, a data line, and a ground line. I've connected VCC to a 3V pin, data to PC5, and then ground to ground obviously.
I'm wondering if someone can help point me in the right direction as far as modifying the example code in the stm32f3XX_hal crate so that I can read the temp/humidity data:
#![no_std]
#![no_main]
use cortex_m::asm;
use cortex_m_rt::entry;
use panic_halt as _;
use stm32f3xx_hal::{self as hal, pac, prelude::*, serial::Serial};
use stm32f3xx_hal::serial::config::Config;
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let mut rcc = dp.RCC.constrain();
let mut flash = dp.FLASH.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
let mut tx = gpioc.pc4;
let mut rx = gpioc.pc5;
let config = Config::default().baudrate(115_200.Bd());
let serial = serial::Serial::new(dp.USART1, (tx, rx), config, clocks, &mut rcc.apb2);
loop {}
}
Am I even in the ballpark with this broken code? Specific questions I have are:
- Do I need to set up a TX pin if I just want to receive data? I'm guessing I have to since to create a new
Serial
it's expecting both atx
and anrx
in thepins
tuple. - Can I receive my data via PC5 or do I need to choose another pin?