From b7049df659e6fcbc05e438873a691e6d1e55ba17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 28 Mar 2017 12:37:34 +0200 Subject: [PATCH] add improvement from thermo-regulator project --- lib/sensor_dht11.c | 11 +++++------ lib/sensor_dht11.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/sensor_dht11.c b/lib/sensor_dht11.c index a3bd701..3433724 100644 --- a/lib/sensor_dht11.c +++ b/lib/sensor_dht11.c @@ -16,12 +16,11 @@ * @file sensor_dht11.c * @author King Kévin * @date 2017 - * @note peripherals used: GPIO and timer @ref sensor_dht11_timer + * @note peripherals used: timer channel @ref sensor_dht11_timer */ /* standard libraries */ #include // standard integer types -#include // general utilities /* STM32 (including CM3) libraries */ #include // Cortex M3 utilities @@ -44,7 +43,7 @@ volatile bool sensor_dht11_measurement_received = false; -/** communication state */ +/** communication states */ volatile enum sensor_dht11_state_t { SENSOR_DHT11_OFF, // no request has started SENSOR_DHT11_HOST_START, // host starts request (and waits >18ms) @@ -52,7 +51,7 @@ volatile enum sensor_dht11_state_t { SENSOR_DHT11_SLAVE_START, // slave responds to request and puts signal low for 80 us and high for 80 us SENSOR_DHT11_SLAVE_BIT, // slave is sending bit by putting signal low for 50 us and high (26-28 us = 0, 70 us = 1) SENSOR_DHT11_MAX -} sensor_dht11_state = SENSOR_DHT11_OFF; +} sensor_dht11_state = SENSOR_DHT11_OFF; /**< current communication state */ /** the bit number being sent (MSb first), up to 40 */ volatile uint8_t sensor_dht11_bit = 0; @@ -106,7 +105,7 @@ bool sensor_dht11_measurement_request(void) if (gpio_get(TIM_CH_PORT(SENSOR_DHT11_TIMER,SENSOR_DHT11_CHANNEL), TIM_CH_PIN(SENSOR_DHT11_TIMER,SENSOR_DHT11_CHANNEL))==0) { // signal should be high per default return false; } - if (TIM_CR1(SENSOR_DHT11_TIMER)&(TIM_CR1_CEN)) { // timer should be off + if (TIM_CR1(TIM(SENSOR_DHT11_TIMER))&(TIM_CR1_CEN)) { // timer should be off return false; } sensor_dht11_reset(); // reset states @@ -126,7 +125,7 @@ struct sensor_dht11_measurement_t sensor_dht11_measurement_decode(void) if (sensor_dht11_bit<40) { // not enough bits received return measurement; } - if (sensor_dht11_bits[0]+sensor_dht11_bits[1]+sensor_dht11_bits[2]+sensor_dht11_bits[3]!=sensor_dht11_bits[4]) { // error in checksum (not really parity bit, as mentioned in the datasheet) + if ((uint8_t)(sensor_dht11_bits[0]+sensor_dht11_bits[1]+sensor_dht11_bits[2]+sensor_dht11_bits[3])!=sensor_dht11_bits[4]) { // error in checksum (not really parity bit, as mentioned in the datasheet) return measurement; } // calculate measured values (byte 1 and 3 should be the factional value but they are always 0) diff --git a/lib/sensor_dht11.h b/lib/sensor_dht11.h index e9e3502..fae7397 100644 --- a/lib/sensor_dht11.h +++ b/lib/sensor_dht11.h @@ -16,7 +16,7 @@ * @file sensor_dht11.h * @author King Kévin * @date 2017 - * @note peripherals used: GPIO @ref sensor_dht11_gpio, timer @ref sensor_dht11_timer + * @note peripherals used: timer channel @ref sensor_dht11_timer (add external pull-up resistor) */ #pragma once