Compare commits
2 Commits
dht11
..
47733fdae4
| Author | SHA1 | Date | |
|---|---|---|---|
| 47733fdae4 | |||
| 2bcf89efe1 |
@@ -1,30 +0,0 @@
|
|||||||
#ifndef __DHT11
|
|
||||||
#define __DHT11
|
|
||||||
|
|
||||||
#define SKIP_LOW while (!(GPIOD->IDR & 0x0800)) {}
|
|
||||||
#define SKIP_HIGH while (GPIOD->IDR & 0x0800) {}
|
|
||||||
|
|
||||||
#define FILL_REGISTER do { \
|
|
||||||
for (int i = 0; i < 8; i++) { \
|
|
||||||
read_register <<= 1; \
|
|
||||||
SKIP_LOW; \
|
|
||||||
read_register |= dht11_measure_high_duration(); \
|
|
||||||
} } while (0)
|
|
||||||
|
|
||||||
struct SysTickConfig {
|
|
||||||
uint32_t ctrl;
|
|
||||||
uint32_t load;
|
|
||||||
uint32_t val;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DHT11_Data {
|
|
||||||
uint8_t humid_integral;
|
|
||||||
uint8_t humid_decimal;
|
|
||||||
uint8_t temp_integral;
|
|
||||||
uint8_t temp_decimal;
|
|
||||||
uint8_t crc;
|
|
||||||
};
|
|
||||||
|
|
||||||
void dht11_show_both(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
#include "main.h"
|
|
||||||
#include "generic_macros.h"
|
|
||||||
#include "dht11.h"
|
|
||||||
|
|
||||||
static struct SysTickConfig stc;
|
|
||||||
static uint32_t *systick_base = (uint32_t *) SysTick_BASE;
|
|
||||||
|
|
||||||
static void wait(uint32_t wait_us)
|
|
||||||
{
|
|
||||||
int target_time = *(systick_base+8);
|
|
||||||
target_time -= wait_us << 4;
|
|
||||||
|
|
||||||
while (*(systick_base+8) > target_time) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dht11_save_systick_state(void)
|
|
||||||
{
|
|
||||||
stc.ctrl = *(systick_base + 0);
|
|
||||||
stc.load = *(systick_base + 4);
|
|
||||||
stc.val = *(systick_base + 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dht11_load_systick_state(void)
|
|
||||||
{
|
|
||||||
*(systick_base + 4) = stc.load;
|
|
||||||
*(systick_base + 8) = stc.val;
|
|
||||||
*(systick_base + 0) = stc.ctrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dht11_init_systick(void)
|
|
||||||
{
|
|
||||||
dht11_save_systick_state();
|
|
||||||
|
|
||||||
*(systick_base + 0) = 0x5; // disable /8 prescaler, no interrupts, enable counting
|
|
||||||
*(systick_base + 4) = 0xFFFFFF; // load largest possible value
|
|
||||||
|
|
||||||
// verify value load
|
|
||||||
if (*(systick_base + 8) == 0)
|
|
||||||
PANIC(0x4000);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t dht11_measure_high_duration(void)
|
|
||||||
{
|
|
||||||
int current_time = *(systick_base+8);
|
|
||||||
SKIP_HIGH;
|
|
||||||
|
|
||||||
// elapsed_time > 49us ? 1 : 0
|
|
||||||
return (current_time - *(systick_base+8)) > (49 << 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dht11_read_value(struct DHT11_Data *data)
|
|
||||||
{
|
|
||||||
dht11_init_systick();
|
|
||||||
|
|
||||||
register uint8_t read_register = 0;
|
|
||||||
|
|
||||||
GPIOD->BSRR = GPIO_PIN_11; // enable DHT11
|
|
||||||
wait(50000); // hold HIGH for 50 ms
|
|
||||||
GPIOD->BSRR = GPIO_PIN_11 << 16; // start signal
|
|
||||||
wait(30000); // hold it for 30 ms
|
|
||||||
GPIOD->BSRR = GPIO_PIN_11; // pull up, DHT will now take control over the connection
|
|
||||||
|
|
||||||
// switch GPIOD 11 to input mode
|
|
||||||
GPIOD->MODER &= 0xFF3FFFFF;
|
|
||||||
|
|
||||||
// read transmission start sequence from DHT11
|
|
||||||
SKIP_HIGH;
|
|
||||||
SKIP_LOW;
|
|
||||||
SKIP_HIGH;
|
|
||||||
|
|
||||||
// read humidity integral
|
|
||||||
FILL_REGISTER;
|
|
||||||
data->humid_integral = read_register;
|
|
||||||
|
|
||||||
// read humidity decimal
|
|
||||||
FILL_REGISTER;
|
|
||||||
data->humid_decimal = read_register;
|
|
||||||
|
|
||||||
// read temperature integral
|
|
||||||
FILL_REGISTER;
|
|
||||||
data->temp_integral = read_register;
|
|
||||||
|
|
||||||
// read temperature decimal
|
|
||||||
FILL_REGISTER;
|
|
||||||
data->temp_decimal = read_register;
|
|
||||||
|
|
||||||
// read crc
|
|
||||||
FILL_REGISTER;
|
|
||||||
data->crc = read_register;
|
|
||||||
|
|
||||||
// switch GPIOD 11 back to output mode
|
|
||||||
GPIOD->MODER |= 0x00900000;
|
|
||||||
|
|
||||||
dht11_load_systick_state();
|
|
||||||
}
|
|
||||||
|
|
||||||
void dht11_show_both(void)
|
|
||||||
{
|
|
||||||
struct DHT11_Data data;
|
|
||||||
dht11_read_value(&data);
|
|
||||||
}
|
|
||||||
+3
-9
@@ -25,7 +25,6 @@
|
|||||||
#include "generic_macros.h"
|
#include "generic_macros.h"
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
#include "external_temp.h"
|
#include "external_temp.h"
|
||||||
#include "dht11.h"
|
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@@ -50,7 +49,6 @@ ADC_HandleTypeDef hadc1;
|
|||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
void ((*executors[])(void)) = {
|
void ((*executors[])(void)) = {
|
||||||
dht11_show_both,
|
|
||||||
external_temp_show_celsius,
|
external_temp_show_celsius,
|
||||||
external_temp_show_fahrenheit
|
external_temp_show_fahrenheit
|
||||||
};
|
};
|
||||||
@@ -106,7 +104,6 @@ int main(void)
|
|||||||
|
|
||||||
GPIOD->ODR = 0xF000;
|
GPIOD->ODR = 0xF000;
|
||||||
display_init();
|
display_init();
|
||||||
HAL_Delay(1000);
|
|
||||||
GPIOD->ODR = 0x0000;
|
GPIOD->ODR = 0x0000;
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
@@ -239,8 +236,7 @@ static void MX_GPIO_Init(void)
|
|||||||
|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
|
|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
|
||||||
|GPIO_PIN_15, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin : PA0 */
|
/*Configure GPIO pin : PA0 */
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||||
@@ -257,10 +253,8 @@ static void MX_GPIO_Init(void)
|
|||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pins : PD11 PD12 PD13 PD14
|
/*Configure GPIO pins : PD12 PD13 PD14 PD15 */
|
||||||
PD15 */
|
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|
|
||||||
|GPIO_PIN_15;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
# Add inputs and outputs from these tool invocations to the build variables
|
||||||
C_SRCS += \
|
C_SRCS += \
|
||||||
../Core/Src/dht11.c \
|
|
||||||
../Core/Src/external-temperature.c \
|
../Core/Src/external-temperature.c \
|
||||||
../Core/Src/external_temp.c \
|
../Core/Src/external_temp.c \
|
||||||
../Core/Src/lcd.c \
|
../Core/Src/lcd.c \
|
||||||
@@ -17,7 +16,6 @@ C_SRCS += \
|
|||||||
../Core/Src/system_stm32f4xx.c
|
../Core/Src/system_stm32f4xx.c
|
||||||
|
|
||||||
OBJS += \
|
OBJS += \
|
||||||
./Core/Src/dht11.o \
|
|
||||||
./Core/Src/external-temperature.o \
|
./Core/Src/external-temperature.o \
|
||||||
./Core/Src/external_temp.o \
|
./Core/Src/external_temp.o \
|
||||||
./Core/Src/lcd.o \
|
./Core/Src/lcd.o \
|
||||||
@@ -29,7 +27,6 @@ OBJS += \
|
|||||||
./Core/Src/system_stm32f4xx.o
|
./Core/Src/system_stm32f4xx.o
|
||||||
|
|
||||||
C_DEPS += \
|
C_DEPS += \
|
||||||
./Core/Src/dht11.d \
|
|
||||||
./Core/Src/external-temperature.d \
|
./Core/Src/external-temperature.d \
|
||||||
./Core/Src/external_temp.d \
|
./Core/Src/external_temp.d \
|
||||||
./Core/Src/lcd.d \
|
./Core/Src/lcd.d \
|
||||||
@@ -48,7 +45,7 @@ Core/Src/%.o Core/Src/%.su Core/Src/%.cyclo: ../Core/Src/%.c Core/Src/subdir.mk
|
|||||||
clean: clean-Core-2f-Src
|
clean: clean-Core-2f-Src
|
||||||
|
|
||||||
clean-Core-2f-Src:
|
clean-Core-2f-Src:
|
||||||
-$(RM) ./Core/Src/dht11.cyclo ./Core/Src/dht11.d ./Core/Src/dht11.o ./Core/Src/dht11.su ./Core/Src/external-temperature.cyclo ./Core/Src/external-temperature.d ./Core/Src/external-temperature.o ./Core/Src/external-temperature.su ./Core/Src/external_temp.cyclo ./Core/Src/external_temp.d ./Core/Src/external_temp.o ./Core/Src/external_temp.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su
|
-$(RM) ./Core/Src/external-temperature.cyclo ./Core/Src/external-temperature.d ./Core/Src/external-temperature.o ./Core/Src/external-temperature.su ./Core/Src/external_temp.cyclo ./Core/Src/external_temp.d ./Core/Src/external_temp.o ./Core/Src/external_temp.su ./Core/Src/lcd.cyclo ./Core/Src/lcd.d ./Core/Src/lcd.o ./Core/Src/lcd.su ./Core/Src/main.cyclo ./Core/Src/main.d ./Core/Src/main.o ./Core/Src/main.su ./Core/Src/stm32f4xx_hal_msp.cyclo ./Core/Src/stm32f4xx_hal_msp.d ./Core/Src/stm32f4xx_hal_msp.o ./Core/Src/stm32f4xx_hal_msp.su ./Core/Src/stm32f4xx_it.cyclo ./Core/Src/stm32f4xx_it.d ./Core/Src/stm32f4xx_it.o ./Core/Src/stm32f4xx_it.su ./Core/Src/syscalls.cyclo ./Core/Src/syscalls.d ./Core/Src/syscalls.o ./Core/Src/syscalls.su ./Core/Src/sysmem.cyclo ./Core/Src/sysmem.d ./Core/Src/sysmem.o ./Core/Src/sysmem.su ./Core/Src/system_stm32f4xx.cyclo ./Core/Src/system_stm32f4xx.d ./Core/Src/system_stm32f4xx.o ./Core/Src/system_stm32f4xx.su
|
||||||
|
|
||||||
.PHONY: clean-Core-2f-Src
|
.PHONY: clean-Core-2f-Src
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"./Core/Src/dht11.o"
|
|
||||||
"./Core/Src/external-temperature.o"
|
"./Core/Src/external-temperature.o"
|
||||||
"./Core/Src/external_temp.o"
|
"./Core/Src/external_temp.o"
|
||||||
"./Core/Src/lcd.o"
|
"./Core/Src/lcd.o"
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ Mcu.Name=STM32F407V(E-G)Tx
|
|||||||
Mcu.Package=LQFP100
|
Mcu.Package=LQFP100
|
||||||
Mcu.Pin0=PA0-WKUP
|
Mcu.Pin0=PA0-WKUP
|
||||||
Mcu.Pin1=PB1
|
Mcu.Pin1=PB1
|
||||||
Mcu.Pin10=PD12
|
Mcu.Pin10=PD13
|
||||||
Mcu.Pin11=PD13
|
Mcu.Pin11=PD14
|
||||||
Mcu.Pin12=PD14
|
Mcu.Pin12=PD15
|
||||||
Mcu.Pin13=PD15
|
Mcu.Pin13=VP_SYS_VS_Systick
|
||||||
Mcu.Pin14=VP_SYS_VS_Systick
|
|
||||||
Mcu.Pin2=PE7
|
Mcu.Pin2=PE7
|
||||||
Mcu.Pin3=PE10
|
Mcu.Pin3=PE10
|
||||||
Mcu.Pin4=PE11
|
Mcu.Pin4=PE11
|
||||||
@@ -36,8 +35,8 @@ Mcu.Pin5=PE12
|
|||||||
Mcu.Pin6=PE13
|
Mcu.Pin6=PE13
|
||||||
Mcu.Pin7=PE14
|
Mcu.Pin7=PE14
|
||||||
Mcu.Pin8=PE15
|
Mcu.Pin8=PE15
|
||||||
Mcu.Pin9=PD11
|
Mcu.Pin9=PD12
|
||||||
Mcu.PinsNb=15
|
Mcu.PinsNb=14
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32F407VGTx
|
Mcu.UserName=STM32F407VGTx
|
||||||
@@ -59,8 +58,6 @@ PA0-WKUP.Locked=true
|
|||||||
PA0-WKUP.Signal=GPXTI0
|
PA0-WKUP.Signal=GPXTI0
|
||||||
PB1.Locked=true
|
PB1.Locked=true
|
||||||
PB1.Signal=ADCx_IN9
|
PB1.Signal=ADCx_IN9
|
||||||
PD11.Locked=true
|
|
||||||
PD11.Signal=GPIO_Output
|
|
||||||
PD12.Locked=true
|
PD12.Locked=true
|
||||||
PD12.Signal=GPIO_Output
|
PD12.Signal=GPIO_Output
|
||||||
PD13.Locked=true
|
PD13.Locked=true
|
||||||
@@ -114,7 +111,7 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
ProjectManager.UnderRoot=true
|
ProjectManager.UnderRoot=true
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true
|
||||||
RCC.AHBFreq_Value=16000000
|
RCC.AHBFreq_Value=16000000
|
||||||
RCC.APB1Freq_Value=16000000
|
RCC.APB1Freq_Value=16000000
|
||||||
RCC.APB1TimFreq_Value=16000000
|
RCC.APB1TimFreq_Value=16000000
|
||||||
|
|||||||
Reference in New Issue
Block a user