From 687767404ede06182a5d1f09ab3b7c66ba5f4d13 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 11 Oct 2022 13:31:06 +0200 Subject: WIP merge fix --- .gitmodules | 4 ---- stm32f091/lib/Si7021_driver_STM32 | 1 - stm32f091/main.c | 9 ++++++++- stm32f091/main.h | 4 +--- stm32f091/makefile | 2 -- stm32f091/sensor.c | 20 ++++++++++++++++---- stm32f091/setup.c | 24 ++++++++++++------------ stm32f091/stm32f0xx_hal_msp.c | 24 ++++++++++++++++++++++-- 8 files changed, 59 insertions(+), 29 deletions(-) delete mode 160000 stm32f091/lib/Si7021_driver_STM32 diff --git a/.gitmodules b/.gitmodules index e7e4ca8..b14eb59 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,7 +10,3 @@ path = stm32f091/lib/FreeRTOS-Kernel url = https://github.com/FreeRTOS/FreeRTOS-Kernel ignore = all -[submodule "stm32f091/lib/Si7021_driver_STM32"] - path = stm32f091/lib/Si7021_driver_STM32 - url = https://github.com/Csatacsibe/Si7021_driver_STM32 - ignore = all diff --git a/stm32f091/lib/Si7021_driver_STM32 b/stm32f091/lib/Si7021_driver_STM32 deleted file mode 160000 index cae65b2..0000000 --- a/stm32f091/lib/Si7021_driver_STM32 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cae65b26c416b7ebe870d0b16886e74b3a652af8 diff --git a/stm32f091/main.c b/stm32f091/main.c index 68e8dd4..61608a8 100644 --- a/stm32f091/main.c +++ b/stm32f091/main.c @@ -1,12 +1,14 @@ #include #include #include +#include #include "main.h" #include "setup.h" #include "sensor.h" +#include "backlog.h" -I2C_HandleTypeDef hi2c2; +I2C_HandleTypeDef hi2c1; UART_HandleTypeDef huart2; int main() { @@ -17,6 +19,11 @@ int main() { MX_USART2_UART_Init(); MX_I2C2_Init(); + HAL_I2C_MspInit(&hi2c1); + + ws_backlog_alloc(24 * 60); + ws_sensor_read(); + xTaskCreate(ws_sensor_read_task, "sensor", 128, NULL, 1, NULL); vTaskStartScheduler(); } diff --git a/stm32f091/main.h b/stm32f091/main.h index 7c13733..b8a1db5 100644 --- a/stm32f091/main.h +++ b/stm32f091/main.h @@ -3,9 +3,7 @@ #include #include -#define hi2c1 hi2c2 - -extern I2C_HandleTypeDef hi2c2; +extern I2C_HandleTypeDef hi2c1; extern UART_HandleTypeDef huart2; void task_1(); diff --git a/stm32f091/makefile b/stm32f091/makefile index ffcb109..5a185de 100644 --- a/stm32f091/makefile +++ b/stm32f091/makefile @@ -19,7 +19,6 @@ SHARED_FLAGS += -I./lib/STM32-base-STM32Cube/CMSIS/STM32F0xx/inc SHARED_FLAGS += -I./lib/STM32-base/startup SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/include SHARED_FLAGS += -I./lib/FreeRTOS-Kernel/portable/GCC/ARM_CM0/ -SHARED_FLAGS += -I./lib/Si7021_driver_STM32/driver/inc/ SHARED_FLAGS += -I. SHARED_FLAGS += -O1 SHARED_FLAGS += -ffunction-sections @@ -66,7 +65,6 @@ OBJS += lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_rcc.o \ lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_tim_ex.o \ lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart.o \ lib/STM32-base-STM32Cube/HAL/STM32F0xx/src/stm32f0xx_hal_uart_ex.o -OBJS += lib/Si7021_driver_STM32/driver/src/Si7021_driver.o .PHONY: flash clean diff --git a/stm32f091/sensor.c b/stm32f091/sensor.c index f2e9e29..fc2fe2a 100644 --- a/stm32f091/sensor.c +++ b/stm32f091/sensor.c @@ -1,14 +1,26 @@ #include #include -#include +#include +#include "main.h" #include "sensor.h" #include "backlog.h" +#define SI7021_ADDRESS ((uint16_t)(0x40) << 1) +#define REG_TEMP ((uint8_t)(0xE3)) +#define REG_HUM ((uint8_t)(0xF5)) + uint8_t ws_sensor_temperature() { - float temp = 0.f; - r_single_Si7021(&temp, Temperature); - return (uint8_t) temp; //TODO: convert with range -> util.h + uint8_t buf[12]; + int16_t val; + float temp_c; + buf[0] = REG_TEMP; + HAL_I2C_Master_Transmit(&hi2c1, SI7021_ADDRESS, buf, 1, HAL_MAX_DELAY); + HAL_I2C_Master_Receive(&hi2c1, SI7021_ADDRESS, buf, 2, HAL_MAX_DELAY); + val = ((int16_t)buf[0]<< 8 ) | (buf[1]); + temp_c= ((175.72*val)/65536) - 46.85; + + return (uint8_t) temp_c; //TODO: convert with range -> util.h } uint8_t ws_sensor_humidity() { diff --git a/stm32f091/setup.c b/stm32f091/setup.c index 42f54b3..d10393c 100644 --- a/stm32f091/setup.c +++ b/stm32f091/setup.c @@ -49,18 +49,18 @@ void SystemClock_Config() { } void MX_I2C2_Init() { - hi2c2.Instance = I2C2; - hi2c2.Init.Timing = 0x20303E5D; - hi2c2.Init.OwnAddress1 = 0; - hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; - hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; - hi2c2.Init.OwnAddress2 = 0; - hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK; - hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; - hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; - if (HAL_I2C_Init(&hi2c2) != HAL_OK) return Error_Handler(); - if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK) return Error_Handler(); - if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK) return Error_Handler(); + hi2c1.Instance = I2C1; + hi2c1.Init.Timing = 0x2000090E; + hi2c1.Init.OwnAddress1 = 0; + hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; + hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; + hi2c1.Init.OwnAddress2 = 0; + hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK; + hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; + hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; + if (HAL_I2C_Init(&hi2c1) != HAL_OK) return Error_Handler(); + if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) return Error_Handler(); + if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) return Error_Handler(); } void MX_USART2_UART_Init() { diff --git a/stm32f091/stm32f0xx_hal_msp.c b/stm32f091/stm32f0xx_hal_msp.c index 8fd7330..d99b334 100644 --- a/stm32f091/stm32f0xx_hal_msp.c +++ b/stm32f091/stm32f0xx_hal_msp.c @@ -1,10 +1,11 @@ +#include + +#include "main.h" #include "stm32f0xx_hal_msp.h" void HAL_MspInit(void) { - return; __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); - HAL_NVIC_SetPriority(PendSV_IRQn, 3, 0); } void HAL_UART_MspInit(UART_HandleTypeDef* huart) { @@ -30,3 +31,22 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { } } +void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if (hi2c->Instance==I2C1) { + __HAL_RCC_GPIOB_CLK_ENABLE(); + /** + * I2C1 GPIO Configuration + * PB8 ------> I2C1_SCL + * PB9 ------> I2C1_SDA + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF1_I2C1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + __HAL_RCC_I2C1_CLK_ENABLE(); + } +} + -- cgit v1.2.3