From fb71edfb6bc0702aa2ee1cc73d0822bbc37674ad Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Sun, 24 Jan 2021 09:23:12 +0000 Subject: working-ish sensor --- .gitmodules | 6 + humidity_sensors/STM8S_StdPeriph_Lib | 1 + humidity_sensors/app/clock.c | 56 ++++ humidity_sensors/app/gpio.c | 77 ++++++ humidity_sensors/app/i2c.h | 3 + humidity_sensors/app/i2c_bb.c | 157 +++++++++++ humidity_sensors/app/main.c | 27 ++ humidity_sensors/app/project.h | 14 + humidity_sensors/app/prototypes.h | 35 +++ humidity_sensors/app/sht20.c | 121 ++++++++ humidity_sensors/app/stm8s_conf.h | 120 ++++++++ humidity_sensors/app/stm8s_it.c | 522 +++++++++++++++++++++++++++++++++++ humidity_sensors/app/stm8s_it.h | 201 ++++++++++++++ humidity_sensors/app/uart.c | 142 ++++++++++ humidity_sensors/app/util.c | 39 +++ humidity_sensors/stm8flash | 1 + 16 files changed, 1522 insertions(+) create mode 160000 humidity_sensors/STM8S_StdPeriph_Lib create mode 100644 humidity_sensors/app/clock.c create mode 100644 humidity_sensors/app/gpio.c create mode 100644 humidity_sensors/app/i2c.h create mode 100644 humidity_sensors/app/i2c_bb.c create mode 100644 humidity_sensors/app/main.c create mode 100644 humidity_sensors/app/project.h create mode 100644 humidity_sensors/app/prototypes.h create mode 100644 humidity_sensors/app/sht20.c create mode 100644 humidity_sensors/app/stm8s_conf.h create mode 100644 humidity_sensors/app/stm8s_it.c create mode 100644 humidity_sensors/app/stm8s_it.h create mode 100644 humidity_sensors/app/uart.c create mode 100644 humidity_sensors/app/util.c create mode 160000 humidity_sensors/stm8flash diff --git a/.gitmodules b/.gitmodules index 6011582..1ac252c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,9 @@ [submodule "boiler-monster/stm32/libopencm3"] path = boiler-monster/stm32/libopencm3 url = git://git.panaceas.org/stm32/libopencm3 +[submodule "humidity_sensors/stm8flash"] + path = humidity_sensors/stm8flash + url = ssh://git@git.panaceas.org/git/stm8/stm8flash/ +[submodule "humidity_sensors/STM8S_StdPeriph_Lib"] + path = humidity_sensors/STM8S_StdPeriph_Lib + url = ssh://git@git.panaceas.org/git/stm8/STM8S_StdPeriph_Lib diff --git a/humidity_sensors/STM8S_StdPeriph_Lib b/humidity_sensors/STM8S_StdPeriph_Lib new file mode 160000 index 0000000..a9ef0b8 --- /dev/null +++ b/humidity_sensors/STM8S_StdPeriph_Lib @@ -0,0 +1 @@ +Subproject commit a9ef0b8cab8dbb2472e29b8692b9c3e2eb866cd0 diff --git a/humidity_sensors/app/clock.c b/humidity_sensors/app/clock.c new file mode 100644 index 0000000..e84a289 --- /dev/null +++ b/humidity_sensors/app/clock.c @@ -0,0 +1,56 @@ +#include "project.h" + +CONST u8 HSIDivFactor[4] = { 1, 2, 4, 8 }; /*!< Holds the different HSI Divider factors */ +CONST u8 CLKPrescTable[8] = { 1, 2, 4, 8, 10, 16, 20, 40 }; /*!< Holds the different CLK prescaler values */ + +u32 +CLK_GetClockFreq (void) +{ + u32 clockfrequency = 0; + CLK_Source_TypeDef clocksource = CLK_SOURCE_HSI; + u8 tmp = 0, presc = 0; + + /* Get CLK source. */ + clocksource = (CLK_Source_TypeDef) CLK->CMSR; + + if (clocksource == CLK_SOURCE_HSI) { + tmp = (u8) (CLK->CKDIVR & CLK_CKDIVR_HSIDIV); + tmp = (u8) (tmp >> 3); + presc = HSIDivFactor[tmp]; + clockfrequency = HSI_VALUE / presc; + } else if (clocksource == CLK_SOURCE_LSI) + clockfrequency = LSI_VALUE; + else + clockfrequency = HSE_VALUE; + + return ((u32) clockfrequency); +} + + +void +clock_init (void) +{ + /* Clear High speed internal clock prescaler */ + CLK->CKDIVR &= (u8) (~CLK_CKDIVR_HSIDIV); + /* Set High speed internal clock prescaler */ + CLK->CKDIVR |= (u8) CLK_PRESCALER_HSIDIV1; +} + +void +CLK_PeripheralClockConfig (CLK_Peripheral_TypeDef CLK_Peripheral, + FunctionalState NewState) +{ + if (((u8) CLK_Peripheral & (u8) 0x10) == 0x00) { + if (NewState != DISABLE) { + CLK->PCKENR1 |= (u8) ((u8) 1 << ((u8) CLK_Peripheral & (u8) 0x0F)); /* Enable the peripheral Clock */ + } else { + CLK->PCKENR1 &= (u8) (~ (u8) (((u8) 1 << ((u8) CLK_Peripheral & (u8) 0x0F)))); /* Disable the peripheral Clock */ + } + } else { + if (NewState != DISABLE) { + CLK->PCKENR2 |= (u8) ((u8) 1 << ((u8) CLK_Peripheral & (u8) 0x0F)); /* Enable the peripheral Clock */ + } else { + CLK->PCKENR2 &= (u8) (~ (u8) (((u8) 1 << ((u8) CLK_Peripheral & (u8) 0x0F)))); /* Disable the peripheral Clock */ + } + } +} diff --git a/humidity_sensors/app/gpio.c b/humidity_sensors/app/gpio.c new file mode 100644 index 0000000..38d57d3 --- /dev/null +++ b/humidity_sensors/app/gpio.c @@ -0,0 +1,77 @@ +#include "project.h" + +u8 +GPIO_ReadInputData (GPIO_TypeDef *GPIOx) +{ + return ((u8) GPIOx->IDR); +} + +void +GPIO_WriteHigh (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef PortPins) +{ + GPIOx->ODR |= (u8) PortPins; +} + +void +GPIO_WriteLow (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef PortPins) +{ + GPIOx->ODR &= (u8) (~PortPins); +} + + +/** + * @brief Initializes the GPIOx according to the specified parameters. + * @param GPIOx : Select the GPIO peripheral number (x = A to I). + * @param GPIO_Pin : This parameter contains the pin number, it can be any value + * of the @ref GPIO_Pin_TypeDef enumeration. + * @param GPIO_Mode : This parameter can be a value of the + * @ref GPIO_Mode_TypeDef enumeration. + * @retval None + */ + +void +GPIO_Init (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef GPIO_Pin, + GPIO_Mode_TypeDef GPIO_Mode) +{ + /*----------------------*/ + /* Check the parameters */ + /*----------------------*/ + + /* Reset corresponding bit to GPIO_Pin in CR2 register */ + GPIOx->CR2 &= (u8) (~ (GPIO_Pin)); + + /*-----------------------------*/ + /* Input/Output mode selection */ + /*-----------------------------*/ + + if ((((u8) (GPIO_Mode)) & (u8) 0x80) != (u8) 0x00) { /* Output mode */ + if ((((u8) (GPIO_Mode)) & (u8) 0x10) != (u8) 0x00) /* High level */ + GPIOx->ODR |= (u8) GPIO_Pin; + else /* Low level */ + GPIOx->ODR &= (u8) (~ (GPIO_Pin)); + + /* Set Output mode */ + GPIOx->DDR |= (u8) GPIO_Pin; + } else { /* Input mode */ + /* Set Input mode */ + GPIOx->DDR &= (u8) (~ (GPIO_Pin)); + } + + /*------------------------------------------------------------------------*/ + /* Pull-Up/Float (Input) or Push-Pull/Open-Drain (Output) modes selection */ + /*------------------------------------------------------------------------*/ + + if ((((u8) (GPIO_Mode)) & (u8) 0x40) != (u8) 0x00) /* Pull-Up or Push-Pull */ + GPIOx->CR1 |= (u8) GPIO_Pin; + else /* Float or Open-Drain */ + GPIOx->CR1 &= (u8) (~ (GPIO_Pin)); + + /*-----------------------------------------------------*/ + /* Interrupt (Input) or Slope (Output) modes selection */ + /*-----------------------------------------------------*/ + + if ((((u8) (GPIO_Mode)) & (u8) 0x20) != (u8) 0x00) /* Interrupt or Slow slope */ + GPIOx->CR2 |= (u8) GPIO_Pin; + else /* No external interrupt or No slope control */ + GPIOx->CR2 &= (u8) (~ (GPIO_Pin)); +} diff --git a/humidity_sensors/app/i2c.h b/humidity_sensors/app/i2c.h new file mode 100644 index 0000000..681e6ab --- /dev/null +++ b/humidity_sensors/app/i2c.h @@ -0,0 +1,3 @@ +#define I2C_WRITE 0 +#define I2C_READ 1 + diff --git a/humidity_sensors/app/i2c_bb.c b/humidity_sensors/app/i2c_bb.c new file mode 100644 index 0000000..7d0d807 --- /dev/null +++ b/humidity_sensors/app/i2c_bb.c @@ -0,0 +1,157 @@ +#include "project.h" + + +#define SCL ((u8) 1 <<4) +#define SDA ((u8) 1 <<5) +#define BANK GPIOB + + +static u8 +set (u8 sda, u8 scl) +{ + u8 ret; + + if (sda) + GPIO_WriteHigh (BANK, SDA); + else + GPIO_WriteLow (BANK, SDA); + + if (scl) + GPIO_WriteHigh (BANK, SCL); + else + GPIO_WriteLow (BANK, SCL); + + delay (4); + //delay_us (10); + ret = (GPIO_ReadInputData (BANK) & SDA) ? 1 : 0; + + return ret; +} + + + + +u8 +i2cb_send (u8 wot) +{ + u8 i; + + for (i = 0; i < 8; ++i) { + set (wot & 0x80, 0); + set (wot & 0x80, 1); + set (wot & 0x80, 0); + wot <<= 1; + } + + set (1, 0); + i = set (1, 1); + set (1, 0); + + return i; +} + +u8 +i2cb_send_addr (u8 addr, u8 rnw) +{ + return i2cb_send (addr << 1 | rnw); +} + +int +i2cb_send_data (u8 d) +{ + return i2cb_send (d); +} + +u8 +i2cb_read (u8 ack) +{ + u8 i, wot = 0; + + for (i = 0; i < 8; ++i) { + wot <<= 1; + set (1, 0); + wot |= set (1, 1); + set (1, 0); + } + + set (ack, 0); + set (ack, 1); + set (ack, 0); + return wot; +} + + +void +i2cb_start (void) +{ + set (1, 1); + set (0, 1); + set (0, 0); +} + +void +i2cb_stop (void) +{ + set (0, 0); + set (0, 1); + set (1, 1); +} + + +int +i2cb_start_transaction (u8 a, u8 rnw) +{ + i2cb_start(); + return i2cb_send_addr (a, rnw); + +} + + +void +i2cb_reset (void) +{ + i2cb_start(); + i2cb_stop(); + i2cb_start(); + i2cb_stop(); +} + + + +#if 0 +void +i2cb_scan (void) +{ + u8 r; + u16 i; + + i2cb_reset(); + + for (i = 0; i < 128; ++i) { + i2cb_start(); + i2cb_stop(); + i2cb_start(); + r = i2cb_send ((i << 1) | I2C_WRITE); + i2cb_stop(); + + if (!r) + printf ("target found at %02x\n", i); + + } + + i2cb_reset(); + +} +#endif + +void +i2cb_init (void) +{ + GPIO_Init (BANK, SDA, GPIO_MODE_OUT_OD_HIZ_SLOW); + GPIO_Init (BANK, SCL, GPIO_MODE_OUT_OD_HIZ_SLOW); + + set (1, 1); + set (0, 1); + set (1, 0); + set (1, 1); +} diff --git a/humidity_sensors/app/main.c b/humidity_sensors/app/main.c new file mode 100644 index 0000000..a94d681 --- /dev/null +++ b/humidity_sensors/app/main.c @@ -0,0 +1,27 @@ +#include "project.h" + +void +main (void) +{ + u8 c; + + clock_init(); + + uart_init(); + i2cb_init(); + + sht20_reset(); + + //enableInterrupts (); + + for (;;) { + printf ("$SNTHD,%s,%s\n", sht20_temp_s(), sht20_humid_s()); + + while (!uart_rx (&c)) { + if (c == 'R') + sht20_reset(); + } + + delay_ms (1000); + } +} diff --git a/humidity_sensors/app/project.h b/humidity_sensors/app/project.h new file mode 100644 index 0000000..1c08c73 --- /dev/null +++ b/humidity_sensors/app/project.h @@ -0,0 +1,14 @@ +#include "stm8s.h" +#include "stdio.h" +#include "stdint.h" + +#include "i2c.h" + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef int8_t s8; +typedef int16_t s16; +typedef int32_t s32; + +#include "prototypes.h" diff --git a/humidity_sensors/app/prototypes.h b/humidity_sensors/app/prototypes.h new file mode 100644 index 0000000..35dbcd9 --- /dev/null +++ b/humidity_sensors/app/prototypes.h @@ -0,0 +1,35 @@ +/* main.c */ +void main(void); +/* util.c */ +void assert_failed(uint8_t *file, uint32_t line); +void delay(volatile uint32_t n); +void delay_ms(volatile uint32_t n); +int putchar(int c); +/* uart.c */ +void uart_tx(uint8_t d); +int uart_rx(uint8_t *d); +void uart_init(void); +/* i2c_bb.c */ +uint8_t i2cb_send(uint8_t wot); +uint8_t i2cb_send_addr(uint8_t addr, uint8_t rnw); +int i2cb_send_data(uint8_t d); +uint8_t i2cb_read(uint8_t ack); +void i2cb_start(void); +void i2cb_stop(void); +int i2cb_start_transaction(uint8_t a, uint8_t rnw); +void i2cb_reset(void); +void i2cb_init(void); +/* clock.c */ +uint32_t CLK_GetClockFreq(void); +void clock_init(void); +void CLK_PeripheralClockConfig(CLK_Peripheral_TypeDef CLK_Peripheral, FunctionalState NewState); +/* gpio.c */ +uint8_t GPIO_ReadInputData(GPIO_TypeDef *GPIOx); +void GPIO_WriteHigh(GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef PortPins); +void GPIO_WriteLow(GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef PortPins); +void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode); +/* sht20.c */ +void sht20_reset(void); +char *sht20_temp_s(void); +char *sht20_humid_s(void); +/* stm8s_it.c */ diff --git a/humidity_sensors/app/sht20.c b/humidity_sensors/app/sht20.c new file mode 100644 index 0000000..d6d648b --- /dev/null +++ b/humidity_sensors/app/sht20.c @@ -0,0 +1,121 @@ +#include "project.h" + +#define SHT20_ADDRESS 0x40 + +#define TRIGGER_TEMP_MEASURE_HOLD 0xE3 +#define TRIGGER_HUMD_MEASURE_HOLD 0xE5 +#define TRIGGER_TEMP_MEASURE_NOHOLD 0xF3 +#define TRIGGER_HUMD_MEASURE_NOHOLD 0xF5 +#define WRITE_USER_REG 0xE6 +#define READ_USER_REG 0xE7 +#define SOFT_RESET 0xFE + + +void +sht20_reset (void) +{ + + i2cb_start_transaction (SHT20_ADDRESS, I2C_WRITE); + i2cb_send_data (SOFT_RESET); + i2cb_stop(); + delay_ms (100); + printf ("$SNTHR\n"); +} + + +char * +sht20_temp_s (void) +{ + u8 h, l, c, s; + s32 t, tf; + float f; + static char ret[8]; + + i2cb_start_transaction (SHT20_ADDRESS, I2C_WRITE); + i2cb_send_data (TRIGGER_TEMP_MEASURE_NOHOLD); + delay_ms (100); + i2cb_start_transaction (SHT20_ADDRESS, I2C_READ); + + h = i2cb_read (0); + l = i2cb_read (0); + c = i2cb_read (1); + + i2cb_stop(); + + t = h; + t <<= 8; + t |= l & 0xfc; + + f = t; + f /= 65536.; + f *= 175.72; + f -= 46.85; + + f *= 100.; + + t = (s32) (f + .5); + + ret[0] = '-'; + + if (t >= 0) + s = 1; + else { + s = 0; + t = -t; + } + + tf = t % 100; + t = t / 100; + + sprintf (&ret[1], "%ld.%02ld", t, tf); + + return &ret[s]; + +} + +char * +sht20_humid_s (void) +{ + u8 h, l, c; + u32 t, tf; + float f; + static char ret[8]; + + i2cb_start_transaction (SHT20_ADDRESS, I2C_WRITE); + i2cb_send_data (TRIGGER_HUMD_MEASURE_NOHOLD); + delay_ms (100); + i2cb_start_transaction (SHT20_ADDRESS, I2C_READ); + + h = i2cb_read (0); + l = i2cb_read (0); + c = i2cb_read (1); + + i2cb_stop(); + + t = h; + t <<= 8; + t |= l & 0xfc; + + f = t; + f /= 65536.; + f *= 125.; + f -= 6.; + + if (f < 0) + f = 0; + + if (f > 100) + f = 100; + + f *= 100.; + + t = (u32) (f + .5); + tf = t % 100; + t = t / 100; + + sprintf (ret, "%ld.%02ld", t, tf); + + + return ret; + +} diff --git a/humidity_sensors/app/stm8s_conf.h b/humidity_sensors/app/stm8s_conf.h new file mode 100644 index 0000000..599f2a7 --- /dev/null +++ b/humidity_sensors/app/stm8s_conf.h @@ -0,0 +1,120 @@ +/** + ****************************************************************************** + * @file stm8s_conf.h + * @author MCD Application Team + * @version V2.3.0 + * @date 16-June-2017 + * @brief This file is used to configure the Library. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2014 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM8S_CONF_H +#define __STM8S_CONF_H + +/* Includes ------------------------------------------------------------------*/ +#include "stm8s.h" + +/* Uncomment the line below to enable peripheral header file inclusion */ +#if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \ + defined(STM8S001) || defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x) + #include "stm8s_adc1.h" +#endif /* (STM8S105) || (STM8S005) || (STM8S103) || (STM8S003) || (STM8S001) || (STM8S903) || (STM8AF626x) || (STM8AF622x) */ +#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || \ + defined(STM8AF62Ax) + #include "stm8s_adc2.h" +#endif /* (STM8S208) || (STM8S207) || (STM8S007) || (STM8AF52Ax) || (STM8AF62Ax) */ +#include "stm8s_awu.h" +#include "stm8s_beep.h" +#if defined(STM8S208) || defined(STM8AF52Ax) + #include "stm8s_can.h" +#endif /* (STM8S208) || (STM8AF52Ax) */ +#include "stm8s_clk.h" +#include "stm8s_exti.h" +#include "stm8s_flash.h" +#include "stm8s_gpio.h" +#include "stm8s_i2c.h" +#include "stm8s_itc.h" +#include "stm8s_iwdg.h" +#include "stm8s_rst.h" +#include "stm8s_spi.h" +#include "stm8s_tim1.h" +#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \ + defined(STM8S003) || defined(STM8S001) || defined(STM8S105) || defined(STM8S005) || defined(STM8AF52Ax) || \ + defined(STM8AF62Ax) || defined(STM8AF626x) + #include "stm8s_tim2.h" +#endif /* (STM8S208) || (STM8S207) || (STM8S007) || (STM8S103) || (STM8S003) || (STM8S001) || (STM8S105) || (STM8S005) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8AF626x) */ +#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ + defined(STM8S005) || defined(STM8AF52Ax) || defined(STM8AF62Ax) || defined(STM8AF626x) + #include "stm8s_tim3.h" +#endif /* (STM8S208) || (STM8S207) || (STM8S007) || (STM8S105) || (STM8S005) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8AF626x) */ +#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \ + defined(STM8S003) || defined(STM8S001) || defined(STM8S105) || defined(STM8S005) || defined(STM8AF52Ax) || \ + defined(STM8AF62Ax) || defined(STM8AF626x) + #include "stm8s_tim4.h" +#endif /* (STM8S208) || (STM8S207) || (STM8S007) || (STM8S103) || (STM8S003) || (STM8S001) || (STM8S105) || (STM8S005) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8AF626x) */ +#if defined(STM8S903) || defined(STM8AF622x) /* SDCC patch: see https://github.com/tenbaht/sduino/tree/master/STM8S_StdPeriph_Driver */ + #include "stm8s_tim5.h" + #include "stm8s_tim6.h" +#endif /* (STM8S903) || (STM8AF622x) */ +#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \ + defined(STM8S003) || defined(STM8S001) || defined(STM8S903) || defined(STM8AF52Ax) || defined(STM8AF62Ax) + #include "stm8s_uart1.h" +#endif /* (STM8S208) || (STM8S207) || (STM8S007) || (STM8S103) || (STM8S003) || (STM8S001) || (STM8S903) || (STM8AF52Ax) || (STM8AF62Ax) */ +#if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x) + #include "stm8s_uart2.h" +#endif /* (STM8S105) || (STM8S005) || (STM8AF626x) */ +#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || \ + defined(STM8AF62Ax) + #include "stm8s_uart3.h" +#endif /* (STM8S208) || (STM8S207) || (STM8S007) || (STM8AF52Ax) || (STM8AF62Ax) */ +#if defined(STM8AF622x) /* SDCC patch: see https://github.com/tenbaht/sduino/tree/master/STM8S_StdPeriph_Driver */ + #include "stm8s_uart4.h" +#endif /* (STM8AF622x) */ +#include "stm8s_wwdg.h" + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Uncomment the line below to expanse the "assert_param" macro in the + Standard Peripheral Library drivers code */ +#define USE_FULL_ASSERT (1) + +/* Exported macro ------------------------------------------------------------*/ +#ifdef USE_FULL_ASSERT + +/** + * @brief The assert_param macro is used for function's parameters check. + * @param expr: If expr is false, it calls assert_failed function + * which reports the name of the source file and the source + * line number of the call that failed. + * If expr is true, it returns no value. + * @retval : None + */ +#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +/* Exported functions ------------------------------------------------------- */ +void assert_failed(uint8_t* file, uint32_t line); +#else +#define assert_param(expr) ((void)0) +#endif /* USE_FULL_ASSERT */ + +#endif /* __STM8S_CONF_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/humidity_sensors/app/stm8s_it.c b/humidity_sensors/app/stm8s_it.c new file mode 100644 index 0000000..5a30096 --- /dev/null +++ b/humidity_sensors/app/stm8s_it.c @@ -0,0 +1,522 @@ +#ifndef PROTOS +/** + ****************************************************************************** + * @file stm8s_it.c + * @author MCD Application Team + * @version V2.2.0 + * @date 30-September-2014 + * @brief Main Interrupt Service Routines. + * This file provides template for all peripherals interrupt service + * routine. + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2014 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm8s_it.h" + +/** @addtogroup Template_Project + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ +/* Public functions ----------------------------------------------------------*/ +/* Public variables ----------------------------------------------------------*/ + +/* +extern u8 g_flag1ms; // flag for 1ms interrupt (for TIM4 ISR) +extern u32 g_count1ms; // 1ms counter (for TIM4 ISR) +*/ + + +#ifdef _COSMIC_ +/** + * @brief Dummy Interrupt routine + * @par Parameters: + * None + * @retval + * None +*/ +INTERRUPT_HANDLER (NonHandledInterrupt, 25) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /*_COSMIC_*/ + +/** + * @brief TRAP Interrupt routine + * @param None + * @retval None + */ +#if !defined(_SDCC_) || (SDCC_VERSION >= 30403) /* SDCC patch: traps require >=v3.4.3 */ +INTERRUPT_HANDLER_TRAP (TRAP_IRQHandler) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif + +/** + * @brief Top Level Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TLI_IRQHandler, 0) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief Auto Wake Up Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (AWU_IRQHandler, 1) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief Clock Controller Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (CLK_IRQHandler, 2) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief External Interrupt PORTA Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (EXTI_PORTA_IRQHandler, 3) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief External Interrupt PORTB Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (EXTI_PORTB_IRQHandler, 4) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief External Interrupt PORTC Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (EXTI_PORTC_IRQHandler, 5) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief External Interrupt PORTD Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (EXTI_PORTD_IRQHandler, 6) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief External Interrupt PORTE Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (EXTI_PORTE_IRQHandler, 7) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +#if defined (STM8S903) || defined (STM8AF622x) +/** + * @brief External Interrupt PORTF Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (EXTI_PORTF_IRQHandler, 8) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S903) || (STM8AF622x) */ + +#if defined (STM8S208) || defined (STM8AF52Ax) +/** + * @brief CAN RX Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (CAN_RX_IRQHandler, 8) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief CAN TX Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (CAN_TX_IRQHandler, 9) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S208) || (STM8AF52Ax) */ + +/** + * @brief SPI Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (SPI_IRQHandler, 10) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief Timer1 Update/Overflow/Trigger/Break Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief Timer1 Capture/Compare Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM1_CAP_COM_IRQHandler, 12) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +#if defined (STM8S903) || defined (STM8AF622x) +/** + * @brief Timer5 Update/Overflow/Break/Trigger Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief Timer5 Capture/Compare Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM5_CAP_COM_IRQHandler, 14) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +#else /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8S103) || (STM8AF62Ax) || (STM8AF52Ax) || (STM8AF626x) */ +/** + * @brief Timer2 Update/Overflow/Break Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM2_UPD_OVF_BRK_IRQHandler, 13) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief Timer2 Capture/Compare Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM2_CAP_COM_IRQHandler, 14) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S903) || (STM8AF622x) */ + +#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ + defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x) +/** + * @brief Timer3 Update/Overflow/Break Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM3_UPD_OVF_BRK_IRQHandler, 15) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief Timer3 Capture/Compare Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM3_CAP_COM_IRQHandler, 16) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8AF62Ax) || (STM8AF52Ax) || (STM8AF626x) */ + +#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \ + defined (STM8S003) || defined(STM8S001) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903) +/** + * @brief UART1 TX Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART1_TX_IRQHandler, 17) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief UART1 RX Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART1_RX_IRQHandler, 18) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S208) || (STM8S207) || (STM8S103) || (STM8S001) || (STM8S903) || (STM8AF62Ax) || (STM8AF52Ax) */ + +#if defined(STM8AF622x) +/** + * @brief UART4 TX Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART4_TX_IRQHandler, 17) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief UART4 RX Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART4_RX_IRQHandler, 18) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8AF622x) */ + +/** + * @brief I2C Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (I2C_IRQHandler, 19) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x) +/** + * @brief UART2 TX interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART2_TX_IRQHandler, 20) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief UART2 RX interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART2_RX_IRQHandler, 21) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S105) || (STM8AF626x) */ + +#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) +/** + * @brief UART3 TX interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART3_TX_IRQHandler, 20) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @brief UART3 RX interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (UART3_RX_IRQHandler, 21) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S208) || (STM8S207) || (STM8AF52Ax) || (STM8AF62Ax) */ + +#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) +/** + * @brief ADC2 interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (ADC2_IRQHandler, 22) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#else /* STM8S105 or STM8S103 or STM8S903 or STM8AF626x or STM8AF622x */ +/** + * @brief ADC1 interrupt routine. + * @par Parameters: + * None + * @retval + * None + */ +INTERRUPT_HANDLER (ADC1_IRQHandler, 22) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S208) || (STM8S207) || (STM8AF52Ax) || (STM8AF62Ax) */ + +#if defined (STM8S903) || defined (STM8AF622x) +/** + * @brief Timer6 Update/Overflow/Trigger Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM6_UPD_OVF_TRG_IRQHandler, 23) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#else /* STM8S208 or STM8S207 or STM8S105 or STM8S103 or STM8AF52Ax or STM8AF62Ax or STM8AF626x */ +/** + * @brief Timer4 Update/Overflow Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (TIM4_UPD_OVF_IRQHandler, 23) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} +#endif /* (STM8S903) || (STM8AF622x) */ + +/** + * @brief Eeprom EEC Interrupt routine. + * @param None + * @retval None + */ +INTERRUPT_HANDLER (EEPROM_EEC_IRQHandler, 24) +{ + /* In order to detect unexpected events during development, + it is recommended to set a breakpoint on the following instruction. + */ +} + +/** + * @} + */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +#endif diff --git a/humidity_sensors/app/stm8s_it.h b/humidity_sensors/app/stm8s_it.h new file mode 100644 index 0000000..0f1636a --- /dev/null +++ b/humidity_sensors/app/stm8s_it.h @@ -0,0 +1,201 @@ +/** + ****************************************************************************** + * @file stm8s_it.h + * @author MCD Application Team + * @version V2.0.4 + * @date 26-April-2018 + * @brief This file contains the headers of the interrupt handlers + ****************************************************************************** + * @attention + * + *

© COPYRIGHT 2014 STMicroelectronics

+ * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM8S_IT_H +#define __STM8S_IT_H + +/* Includes ------------------------------------------------------------------*/ +#include "stm8s.h" + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +#ifdef _COSMIC_ + void _stext(void); /* RESET startup routine */ + INTERRUPT void NonHandledInterrupt(void); +#endif /* _COSMIC_ */ + +// SDCC patch: requires separate handling for SDCC (see below) +#if !defined(_RAISONANCE_) && !defined(_SDCC_) + INTERRUPT void TRAP_IRQHandler(void); /* TRAP */ + INTERRUPT void TLI_IRQHandler(void); /* TLI */ + INTERRUPT void AWU_IRQHandler(void); /* AWU */ + INTERRUPT void CLK_IRQHandler(void); /* CLOCK */ + INTERRUPT void EXTI_PORTA_IRQHandler(void); /* EXTI PORTA */ + INTERRUPT void EXTI_PORTB_IRQHandler(void); /* EXTI PORTB */ + INTERRUPT void EXTI_PORTC_IRQHandler(void); /* EXTI PORTC */ + INTERRUPT void EXTI_PORTD_IRQHandler(void); /* EXTI PORTD */ + INTERRUPT void EXTI_PORTE_IRQHandler(void); /* EXTI PORTE */ + +#if defined(STM8S903) || defined(STM8AF622x) // SDCC patch: add STM8AF622x + INTERRUPT void EXTI_PORTF_IRQHandler(void); /* EXTI PORTF */ +#endif /* (STM8S903) || (STM8AF622x) */ + +#if defined (STM8S208) || defined (STM8AF52Ax) + INTERRUPT void CAN_RX_IRQHandler(void); /* CAN RX */ + INTERRUPT void CAN_TX_IRQHandler(void); /* CAN TX/ER/SC */ +#endif /* (STM8S208) || (STM8AF52Ax) */ + + INTERRUPT void SPI_IRQHandler(void); /* SPI */ + INTERRUPT void TIM1_CAP_COM_IRQHandler(void); /* TIM1 CAP/COM */ + INTERRUPT void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void); /* TIM1 UPD/OVF/TRG/BRK */ + +#if defined(STM8S903) || defined(STM8AF622x) // SDCC patch: add STM8AF622x + INTERRUPT void TIM5_UPD_OVF_BRK_TRG_IRQHandler(void); /* TIM5 UPD/OVF/BRK/TRG */ + INTERRUPT void TIM5_CAP_COM_IRQHandler(void); /* TIM5 CAP/COM */ +#else /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8S103) || (STM8S001) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8A626x) */ + INTERRUPT void TIM2_UPD_OVF_BRK_IRQHandler(void); /* TIM2 UPD/OVF/BRK */ + INTERRUPT void TIM2_CAP_COM_IRQHandler(void); /* TIM2 CAP/COM */ +#endif /* (STM8S903) || (STM8AF622x) */ + +#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ + defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined (STM8AF626x) + INTERRUPT void TIM3_UPD_OVF_BRK_IRQHandler(void); /* TIM3 UPD/OVF/BRK */ + INTERRUPT void TIM3_CAP_COM_IRQHandler(void); /* TIM3 CAP/COM */ +#endif /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8A626x) */ + +#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \ + defined(STM8S003) || defined(STM8S001) || defined(STM8AF52Ax) || defined(STM8AF62Ax) || defined(STM8S903) + INTERRUPT void UART1_TX_IRQHandler(void); /* UART1 TX */ + INTERRUPT void UART1_RX_IRQHandler(void); /* UART1 RX */ +#endif /* (STM8S208) || (STM8S207) || (STM8S007) || (STM8S103) || (STM8S003) || (STM8S001) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8S903) */ + +#if defined (STM8AF622x) // SDCC patch: add STM8AF622x + INTERRUPT void UART4_TX_IRQHandler(void); /* UART4 TX */ + INTERRUPT void UART4_RX_IRQHandler(void); /* UART4 RX */ +#endif /* (STM8AF622x) */ + + INTERRUPT void I2C_IRQHandler(void); /* I2C */ + +#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x) + INTERRUPT void UART2_RX_IRQHandler(void); /* UART2 RX */ + INTERRUPT void UART2_TX_IRQHandler(void); /* UART2 TX */ +#endif /* (STM8S105) || (STM8S005) || (STM8AF626x) */ + +#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) + INTERRUPT void UART3_RX_IRQHandler(void); /* UART3 RX */ + INTERRUPT void UART3_TX_IRQHandler(void); /* UART3 TX */ +#endif /* (STM8S207) || (STM8S007) || (STM8S208) || (STM8AF52Ax) || (STM8AF62Ax) */ + +#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) + INTERRUPT void ADC2_IRQHandler(void); /* ADC2 */ +#else /* (STM8S105) || (STM8S103) || (STM8S903) || (STM8AF622x) */ + INTERRUPT void ADC1_IRQHandler(void); /* ADC1 */ +#endif /* (STM8S207) || (STM8S007) || (STM8S208) || (STM8AF52Ax) || (STM8AF62Ax) */ + +#if defined(STM8S903) || defined(STM8AF622x) // SDCC patch: add STM8AF622x + INTERRUPT void TIM6_UPD_OVF_TRG_IRQHandler(void); /* TIM6 UPD/OVF/TRG */ +#else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */ + INTERRUPT void TIM4_UPD_OVF_IRQHandler(void); /* TIM4 UPD/OVF */ +#endif /* (STM8S903) || (STM8AF622x) */ + INTERRUPT void EEPROM_EEC_IRQHandler(void); /* EEPROM ECC CORRECTION */ + + +// SDCC patch: __interrupt keyword required after function name --> requires new block +#elif defined (_SDCC_) + + INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler); /* TRAP */ + INTERRUPT_HANDLER(TLI_IRQHandler, 0); /* TLI */ + INTERRUPT_HANDLER(AWU_IRQHandler, 1); /* AWU */ + INTERRUPT_HANDLER(CLK_IRQHandler, 2); /* CLOCK */ + INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3); /* EXTI PORTA */ + INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4); /* EXTI PORTB */ + INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5); /* EXTI PORTC */ +// INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6); /* EXTI PORTD */ + INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7); /* EXTI PORTE */ + +#if defined(STM8S903) || defined(STM8AF622x) + INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler, 8); /* EXTI PORTF */ +#endif /* (STM8S903) || (STM8AF622x) */ + +#if defined (STM8S208) || defined (STM8AF52Ax) + INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8); /* CAN RX */ + INTERRUPT_HANDLER(CAN_TX_IRQHandler, 9); /* CAN TX/ER/SC */ +#endif /* (STM8S208) || (STM8AF52Ax) */ + + INTERRUPT_HANDLER(SPI_IRQHandler, 10); /* SPI */ + INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11); /* TIM1 UPD/OVF/TRG/BRK */ + INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12); /* TIM1 CAP/COM */ + +#if defined(STM8S903) || defined(STM8AF622x) + INTERRUPT_HANDLER(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13); /* TIM5 UPD/OVF/BRK/TRG */ + INTERRUPT_HANDLER(TIM5_CAP_COM_IRQHandler, 14); /* TIM5 CAP/COM */ +#else /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8S103) || (STM8S001) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8A626x) */ + INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13); /* TIM2 UPD/OVF/BRK */ + INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14); /* TIM2 CAP/COM */ +#endif /* (STM8S903) || (STM8AF622x) */ + +#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ + defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined (STM8AF626x) + INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15); /* TIM3 UPD/OVF/BRK */ + INTERRUPT_HANDLER(TIM3_CAP_COM_IRQHandler, 16); /* TIM3 CAP/COM */ +#endif /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8AF52Ax) || (STM8AF62Ax) || (STM8A626x) */ + +#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \ + defined(STM8S003) || defined(STM8S001) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined (STM8S903) + INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17); /* UART1 TX */ + INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18); /* UART1 RX */ +#endif /* (STM8S208) || (STM8S207) || (STM8S903) || (STM8S103) || (STM8S001) || (STM8AF52Ax) || (STM8AF62Ax) */ + +#if defined (STM8AF622x) + INTERRUPT_HANDLER(UART4_TX_IRQHandler, 17); /* UART4 TX */ + INTERRUPT_HANDLER(UART4_RX_IRQHandler, 18); /* UART4 RX */ +#endif /* (STM8AF622x) */ + + INTERRUPT_HANDLER(I2C_IRQHandler, 19); /* I2C */ + +#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x) + INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20); /* UART2 TX */ + INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21); /* UART2 RX */ +#endif /* (STM8S105) || (STM8AF626x) */ + +#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) + INTERRUPT_HANDLER(UART3_RX_IRQHandler, 20); /* UART3 RX */ + INTERRUPT_HANDLER(UART3_TX_IRQHandler, 21); /* UART3 TX */ +#endif /* (STM8S207) || (STM8S208) || (STM8AF62Ax) || (STM8AF52Ax) */ + +#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax) + INTERRUPT_HANDLER(ADC2_IRQHandler, 22); /* ADC2 */ +#else /* (STM8S105) || (STM8S103) || (STM8S903) || (STM8AF622x) */ + INTERRUPT_HANDLER(ADC1_IRQHandler, 22); /* ADC1 */ +#endif /* (STM8S207) || (STM8S208) || (STM8AF62Ax) || (STM8AF52Ax) */ + +#if defined(STM8S903) || defined(STM8AF622x) + INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23); /* TIM6 UPD/OVF/TRG */ +#else /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8S103) || (STM8AF62Ax) || (STM8AF52Ax) || (STM8AF626x) */ + INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23); /* TIM4 UPD/OVF */ +#endif /* (STM8S903) || (STM8AF622x) */ + INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24); /* EEPROM ECC CORRECTION */ + +#endif /* !(_RAISONANCE_) && !(_SDCC_) */ + +#endif /* __STM8S_IT_H */ + + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/humidity_sensors/app/uart.c b/humidity_sensors/app/uart.c new file mode 100644 index 0000000..78eafc4 --- /dev/null +++ b/humidity_sensors/app/uart.c @@ -0,0 +1,142 @@ +#include "project.h" +static void +_uart_deinit (void) +{ + /* Clear the Idle Line Detected bit in the status register by a read + to the UART1_SR register followed by a Read to the UART1_DR register */ + (void) UART1->SR; + (void) UART1->DR; + + UART1->BRR2 = UART1_BRR2_RESET_VALUE; /* Set UART1_BRR2 to reset value 0x00 */ + UART1->BRR1 = UART1_BRR1_RESET_VALUE; /* Set UART1_BRR1 to reset value 0x00 */ + + UART1->CR1 = UART1_CR1_RESET_VALUE; /* Set UART1_CR1 to reset value 0x00 */ + UART1->CR2 = UART1_CR2_RESET_VALUE; /* Set UART1_CR2 to reset value 0x00 */ + UART1->CR3 = UART1_CR3_RESET_VALUE; /* Set UART1_CR3 to reset value 0x00 */ + UART1->CR4 = UART1_CR4_RESET_VALUE; /* Set UART1_CR4 to reset value 0x00 */ + UART1->CR5 = UART1_CR5_RESET_VALUE; /* Set UART1_CR5 to reset value 0x00 */ + + UART1->GTR = UART1_GTR_RESET_VALUE; + UART1->PSCR = UART1_PSCR_RESET_VALUE; +} + +static void +_uart_init (u32 BaudRate, UART1_WordLength_TypeDef WordLength, + UART1_StopBits_TypeDef StopBits, UART1_Parity_TypeDef Parity, + UART1_SyncMode_TypeDef SyncMode, UART1_Mode_TypeDef Mode) +{ + u32 BaudRate_Mantissa = 0, BaudRate_Mantissa100 = 0; + + /* Clear the word length bit */ + UART1->CR1 &= (u8) (~UART1_CR1_M); + + /* Set the word length bit according to UART1_WordLength value */ + UART1->CR1 |= (u8) WordLength; + + /* Clear the STOP bits */ + UART1->CR3 &= (u8) (~UART1_CR3_STOP); + /* Set the STOP bits number according to UART1_StopBits value */ + UART1->CR3 |= (u8) StopBits; + + /* Clear the Parity Control bit */ + UART1->CR1 &= (u8) (~ (UART1_CR1_PCEN | UART1_CR1_PS)); + /* Set the Parity Control bit to UART1_Parity value */ + UART1->CR1 |= (u8) Parity; + + /* Clear the LSB mantissa of UART1DIV */ + UART1->BRR1 &= (u8) (~UART1_BRR1_DIVM); + /* Clear the MSB mantissa of UART1DIV */ + UART1->BRR2 &= (u8) (~UART1_BRR2_DIVM); + /* Clear the Fraction bits of UART1DIV */ + UART1->BRR2 &= (u8) (~UART1_BRR2_DIVF); + + /* Set the UART1 BaudRates in BRR1 and BRR2 registers according to UART1_BaudRate value */ + BaudRate_Mantissa = ((u32) CLK_GetClockFreq() / (BaudRate << 4)); + BaudRate_Mantissa100 = + (((u32) CLK_GetClockFreq() * 100) / (BaudRate << 4)); + /* Set the fraction of UART1DIV */ + UART1->BRR2 |= + (u8) ((u8) + (((BaudRate_Mantissa100 - + (BaudRate_Mantissa * 100)) << 4) / 100) & (u8) 0x0F); + /* Set the MSB mantissa of UART1DIV */ + UART1->BRR2 |= (u8) ((BaudRate_Mantissa >> 4) & (u8) 0xF0); + /* Set the LSB mantissa of UART1DIV */ + UART1->BRR1 |= (u8) BaudRate_Mantissa; + + /* Disable the Transmitter and Receiver before setting the LBCL, CPOL and CPHA bits */ + UART1->CR2 &= (u8) ~ (UART1_CR2_TEN | UART1_CR2_REN); + /* Clear the Clock Polarity, lock Phase, Last Bit Clock pulse */ + UART1->CR3 &= + (u8) ~ (UART1_CR3_CPOL | UART1_CR3_CPHA | UART1_CR3_LBCL); + /* Set the Clock Polarity, lock Phase, Last Bit Clock pulse */ + UART1->CR3 |= (u8) ((u8) SyncMode & (u8) (UART1_CR3_CPOL | + UART1_CR3_CPHA | + UART1_CR3_LBCL)); + + if ((u8) (Mode & UART1_MODE_TX_ENABLE)) { + /* Set the Transmitter Enable bit */ + UART1->CR2 |= (u8) UART1_CR2_TEN; + } else { + /* Clear the Transmitter Disable bit */ + UART1->CR2 &= (u8) (~UART1_CR2_TEN); + } + + if ((u8) (Mode & UART1_MODE_RX_ENABLE)) { + /* Set the Receiver Enable bit */ + UART1->CR2 |= (u8) UART1_CR2_REN; + } else { + /* Clear the Receiver Disable bit */ + UART1->CR2 &= (u8) (~UART1_CR2_REN); + } + + /* Set the Clock Enable bit, lock Polarity, lock Phase and Last Bit Clock + pulse bits according to UART1_Mode value */ + if ((u8) (SyncMode & UART1_SYNCMODE_CLOCK_DISABLE)) { + /* Clear the Clock Enable bit */ + UART1->CR3 &= (u8) (~UART1_CR3_CKEN); + } else + UART1->CR3 |= (u8) ((u8) SyncMode & UART1_CR3_CKEN); +} + +void +uart_tx (u8 d) +{ + while (! (UART1->SR & UART1_FLAG_TXE)); + + UART1->DR = d; +} + +int +uart_rx (u8 *d) +{ + if (UART1->SR & UART1_FLAG_RXNE) { + *d = UART1->DR; + return 0; + } + + return -1; +} + + +void +uart_init (void) +{ + CLK_PeripheralClockConfig (CLK_PERIPHERAL_UART1, ENABLE); + + _uart_deinit(); + + /* UART1 configuration ------------------------------------------------------ */ + /* UART1 configured as follow: + - BaudRate = 115200 baud + - Word Length = 8 Bits + - One Stop Bit + - No parity + - Receive and transmit enabled + - UART1 Clock disabled + */ + _uart_init ((u32) 115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, + UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, + UART1_MODE_TXRX_ENABLE); + +} diff --git a/humidity_sensors/app/util.c b/humidity_sensors/app/util.c new file mode 100644 index 0000000..04a17ae --- /dev/null +++ b/humidity_sensors/app/util.c @@ -0,0 +1,39 @@ +#include "project.h" + +#if 0 +void +assert_failed (u8 *file, u32 line) +{ + // avoid compiler warnings + (void) file; + (void) line; + + /* Infinite loop */ + while (1) { + } +} +#endif + +void +delay (__IO u32 n) +{ + /* Decrement nCount value */ + while (n--); +} + +void +delay_ms (__IO u32 n) +{ + while (n--) + delay (483); +} + +int +putchar (int c) +{ + if (c == '\n') + uart_tx ('\r'); + + uart_tx (c); + return (c); +} diff --git a/humidity_sensors/stm8flash b/humidity_sensors/stm8flash new file mode 160000 index 0000000..cdafc46 --- /dev/null +++ b/humidity_sensors/stm8flash @@ -0,0 +1 @@ +Subproject commit cdafc4638d714ed1a5250cac794b5b28e5cbfa09 -- cgit v1.2.3