27 #include <libopencmsis/core_cm3.h> 28 #include <libopencm3/cm3/nvic.h> 29 #include <libopencm3/stm32/rcc.h> 30 #include <libopencm3/stm32/gpio.h> 31 #include <libopencm3/stm32/timer.h> 40 #define SENSOR_DHT11_TIMER 3 41 #define SENSOR_DHT11_CHANNEL 1 42 #define SENSOR_DHT11_JITTER 0.1 45 volatile bool sensor_dht11_measurement_received = false; 50 SENSOR_DHT11_HOST_START,
51 SENSOR_DHT11_HOST_STARTED,
52 SENSOR_DHT11_SLAVE_START,
53 SENSOR_DHT11_SLAVE_BIT,
55 } sensor_dht11_state = SENSOR_DHT11_OFF;
67 sensor_dht11_state = SENSOR_DHT11_OFF;
103 if (sensor_dht11_state!=SENSOR_DHT11_OFF) {
118 sensor_dht11_state = SENSOR_DHT11_HOST_START;
144 if (sensor_dht11_state==SENSOR_DHT11_HOST_START) {
146 sensor_dht11_state = SENSOR_DHT11_HOST_STARTED;
155 switch (sensor_dht11_state) {
156 case (SENSOR_DHT11_HOST_STARTED):
157 sensor_dht11_state = SENSOR_DHT11_SLAVE_START;
159 case (SENSOR_DHT11_SLAVE_START):
161 sensor_dht11_state = SENSOR_DHT11_SLAVE_BIT;
166 case (SENSOR_DHT11_SLAVE_BIT):
library to query measurements from Aosong DHT11 temperature and relative humidity sensor (API) ...
#define RCC_TIM_CH(x, y)
get RCC for port based on TIMx_CHy identifier
#define TIM_ISR(x)
get interrupt service routine for timer base on TIM identifier
#define NVIC_TIM_IRQ(x)
get NVIC IRQ for timer base on TIM identifier
#define TIM_SR_CCIF(x)
get TIM_SR_CCxIF based on CHx identifier
static void sensor_dht11_reset(void)
reset all states
#define TIM_DIER_CCIE(x)
get TIM_DIER_CCxIE based on CHx identifier
global definitions and methods (API)
#define TIM_CCR(x, y)
get TIM_CCRy register based on TIMx_CHy identifier
#define SENSOR_DHT11_CHANNEL
channel used as input capture
sensor_dht11_state_t
communication state
void sensor_dht11_setup(void)
setup peripherals to communicate with sensor
volatile bool sensor_dht11_measurement_received
a measurement response has been received
volatile uint8_t sensor_dht11_bit
the bit number being sent (MSb first), up to 40
#define RCC_TIM(x)
get RCC for timer based on TIM identifier
#define TIM_CH_PIN(x, y)
get pin based on TIMx_CHy identifier
#define SENSOR_DHT11_TIMER
timer peripheral
#define TIM_IC(x)
get TIM_IC based on CHx identifier
bool sensor_dht11_measurement_request(void)
request measurement from sensor
#define TIM_IC_IN_TI(x)
get TIM_IC_IN_TI based on CHx identifier
#define TIM_CH_PORT(x, y)
get port based on TIMx_CHy identifier
measurement returned by sensor
struct sensor_dht11_measurement_t sensor_dht11_measurement_decode(void)
decode received measurement
uint8_t humidity
relative humidity in RH (20-95)
volatile uint8_t sensor_dht11_bits[5]
the 40 bits (5 bytes) being sent by the device
#define TIM(x)
get TIM based on TIM identifier
uint8_t temperature
temperature in °C (0-50)
#define SENSOR_DHT11_JITTER
signal timing jitter tolerated in timing