# HG changeset patch # User matthewreed # Date 2018-08-25 12:38:32 # Node ID df3cd2f9bf90febca2966eee4d7d7fb09c176ae5 # Parent 3ffc65a90345ea7d0a180664e6f7335ce31923c5 Started to add support for sgp30 diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -69,6 +69,8 @@ Src/stm32f0xx_hal_msp.c \ Src/stm32f0xx_it.c \ Src/system_stm32f0xx.c \ Src/system.c \ +Src/i2c.c \ +Src/sgp30.c \ hydrobot-sharedlibs/src/can_buffer.c \ hydrobot-sharedlibs/src/can.c \ hydrobot-sharedlibs/src/flash.c \ @@ -164,6 +166,9 @@ LDFLAGS = $(MCU) -specs=nano.specs -T$(L # default action: build all all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin +# flash via serial wire debug +flash: all + st-flash --reset write $(BUILD_DIR)/$(TARGET).bin 0x8000000 ####################################### # build the application diff --git a/Src/main.c b/Src/main.c --- a/Src/main.c +++ b/Src/main.c @@ -4,7 +4,8 @@ #include "system.h" #include "led.h" #include "protocol.h" - +#include "i2c.h" +#include "sgp30.h" int main(void) { @@ -12,6 +13,8 @@ int main(void) HAL_Init(); system_init(); gpio_init(); + //sgp30_init(); + //sgp30_IAQinit(); protocol_init(PROTOMODULE); @@ -47,13 +50,13 @@ int main(void) if (HAL_GetTick() - loop_timer_200ms >= 200) { - loop_timer_200ms = HAL_GetTick(); } if (HAL_GetTick() - loop_timer_1s >= 1000) { - + //sgp30_IAQmeasure(); + //protocol_send_data(NONE, 0, sgp30_get_tvoc()); loop_timer_1s = HAL_GetTick(); } if (HAL_GetTick() - loop_timer_2s >= 2000) diff --git a/Src/stm32f0xx_hal_msp.c b/Src/stm32f0xx_hal_msp.c --- a/Src/stm32f0xx_hal_msp.c +++ b/Src/stm32f0xx_hal_msp.c @@ -121,6 +121,44 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef } +void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) +{ + + GPIO_InitTypeDef GPIO_InitStruct; + if(hi2c->Instance==I2C1) + { + /* USER CODE BEGIN I2C1_MspInit 0 */ + + RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct; + + /*##-1- Configure the I2C clock source. The clock is derived from the SYSCLK #*/ + RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C1; + RCC_PeriphCLKInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK; + HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct); + + /* USER CODE END I2C1_MspInit 0 */ + + /**I2C1 GPIO Configuration + PB6 ------> I2C1_SCL + PB7 ------> I2C1_SDA + */ + + GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + /* Peripheral clock enable */ + __HAL_RCC_I2C1_CLK_ENABLE(); + /* USER CODE BEGIN I2C1_MspInit 1 */ + + /* USER CODE END I2C1_MspInit 1 */ + } + +} + void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm) {