summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--humidity_sensors/.gitignore1
-rw-r--r--humidity_sensors/DISTRIB/en.stsw-stm8069.zipbin0 -> 11235965 bytes
-rw-r--r--humidity_sensors/DOC/8S003F3.pdfbin0 -> 1542433 bytes
-rw-r--r--humidity_sensors/DOC/GATEMODE-YD3082E_C269866.pdfbin0 -> 653185 bytes
-rw-r--r--humidity_sensors/DOC/RM0016.pdfbin0 -> 9939004 bytes
-rw-r--r--humidity_sensors/DOC/Sensirion_Humidity_Sensors_SHT20_Datasheet-1274196.pdfbin0 -> 554833 bytes
-rw-r--r--humidity_sensors/DOC/XL7005A datasheet-English.pdfbin0 -> 246457 bytes
-rw-r--r--humidity_sensors/DOC/cd00190271-stm8s-series-and-stm8af-series-8bit-microcontrollers-stmicroelectronics.pdfbin0 -> 9939004 bytes
-rw-r--r--humidity_sensors/DOC/stm8s003f3.pdfbin0 -> 1542433 bytes
-rw-r--r--humidity_sensors/app/Makefile51
-rw-r--r--humidity_sensors/app/awu.c70
-rw-r--r--humidity_sensors/app/main.c7
-rw-r--r--humidity_sensors/app/prototypes.h27
-rw-r--r--humidity_sensors/app/stm8s_it.c2
m---------humidity_sensors/stm8flash0
-rwxr-xr-xtasmota-config/configure-humidifier74
16 files changed, 218 insertions, 14 deletions
diff --git a/humidity_sensors/.gitignore b/humidity_sensors/.gitignore
new file mode 100644
index 0000000..d63b3df
--- /dev/null
+++ b/humidity_sensors/.gitignore
@@ -0,0 +1 @@
+app/build
diff --git a/humidity_sensors/DISTRIB/en.stsw-stm8069.zip b/humidity_sensors/DISTRIB/en.stsw-stm8069.zip
new file mode 100644
index 0000000..e4815a6
--- /dev/null
+++ b/humidity_sensors/DISTRIB/en.stsw-stm8069.zip
Binary files differ
diff --git a/humidity_sensors/DOC/8S003F3.pdf b/humidity_sensors/DOC/8S003F3.pdf
new file mode 100644
index 0000000..d9aea9b
--- /dev/null
+++ b/humidity_sensors/DOC/8S003F3.pdf
Binary files differ
diff --git a/humidity_sensors/DOC/GATEMODE-YD3082E_C269866.pdf b/humidity_sensors/DOC/GATEMODE-YD3082E_C269866.pdf
new file mode 100644
index 0000000..8601f63
--- /dev/null
+++ b/humidity_sensors/DOC/GATEMODE-YD3082E_C269866.pdf
Binary files differ
diff --git a/humidity_sensors/DOC/RM0016.pdf b/humidity_sensors/DOC/RM0016.pdf
new file mode 100644
index 0000000..39af8da
--- /dev/null
+++ b/humidity_sensors/DOC/RM0016.pdf
Binary files differ
diff --git a/humidity_sensors/DOC/Sensirion_Humidity_Sensors_SHT20_Datasheet-1274196.pdf b/humidity_sensors/DOC/Sensirion_Humidity_Sensors_SHT20_Datasheet-1274196.pdf
new file mode 100644
index 0000000..ad7347e
--- /dev/null
+++ b/humidity_sensors/DOC/Sensirion_Humidity_Sensors_SHT20_Datasheet-1274196.pdf
Binary files differ
diff --git a/humidity_sensors/DOC/XL7005A datasheet-English.pdf b/humidity_sensors/DOC/XL7005A datasheet-English.pdf
new file mode 100644
index 0000000..be3dd82
--- /dev/null
+++ b/humidity_sensors/DOC/XL7005A datasheet-English.pdf
Binary files differ
diff --git a/humidity_sensors/DOC/cd00190271-stm8s-series-and-stm8af-series-8bit-microcontrollers-stmicroelectronics.pdf b/humidity_sensors/DOC/cd00190271-stm8s-series-and-stm8af-series-8bit-microcontrollers-stmicroelectronics.pdf
new file mode 100644
index 0000000..39af8da
--- /dev/null
+++ b/humidity_sensors/DOC/cd00190271-stm8s-series-and-stm8af-series-8bit-microcontrollers-stmicroelectronics.pdf
Binary files differ
diff --git a/humidity_sensors/DOC/stm8s003f3.pdf b/humidity_sensors/DOC/stm8s003f3.pdf
new file mode 100644
index 0000000..d9aea9b
--- /dev/null
+++ b/humidity_sensors/DOC/stm8s003f3.pdf
Binary files differ
diff --git a/humidity_sensors/app/Makefile b/humidity_sensors/app/Makefile
new file mode 100644
index 0000000..01d0888
--- /dev/null
+++ b/humidity_sensors/app/Makefile
@@ -0,0 +1,51 @@
+CSRCS=main.c util.c uart.c i2c_bb.c clock.c gpio.c sht20.c stm8s_it.c awu.c
+PROG=build/main.hex
+LIBS=
+SPL_CSRCS =
+
+SPL_ROOT=../STM8S_StdPeriph_Lib
+SPL_SRC = $(SPL_ROOT)/Libraries/STM8S_StdPeriph_Driver/src
+SPL_INC = $(SPL_ROOT)/Libraries/STM8S_StdPeriph_Driver/inc
+
+CFLAGS=--opt-code-size --std-sdcc99 --all-callee-saves --verbose --stack-auto --fverbose-asm --float-reent
+CPPFLAGS=-I./ -I${SPL_INC} -DSTM8S003
+CC=sdcc-sdcc -mstm8
+AS=sdcc-sdasstm8
+STM8FLASH=../stm8flash/stm8flash
+
+LIBOBJ=${SPL_CSRCS:%.c=build/%.rel}
+OBJS=${CSRCS:%.c=build/%.rel} ${SPL_CSRCS:%.c=build/%.rel}
+
+${PROG}: ${OBJS}
+ ${CC} ${CFLAGS} ${CPPFLAGS} -o $@ ${OBJS}
+
+build/%.rel:${SPL_SRC}/%.c
+ ${CC} ${CFLAGS} ${CPPFLAGS} -o $@ -c $<
+
+build/%.rel:%.c
+ ${CC} ${CFLAGS} ${CPPFLAGS} -o $@ -c $<
+
+
+flash: ${PROG} ${STM8FLASH}
+ ${STM8FLASH} -c stlinkv2 -p stm8s003?3 -s flash -w ${PROG}
+
+${STM8FLASH}:
+ make -C $(dir $@)
+
+
+tidy:
+ astyle -A3 -s2 --attach-extern-c -L -c -w -Y -m0 -f -p -H -U -k3 -xj -xd ${CSRCS}
+
+protos:
+ echo > prototypes.h
+ cproto -E "${CC} -E ${CPPFLAGS} -D__trap= -D__interrupt\(a\)= -DPROTOS" ${CSRCS} > prototypes.h.tmp
+ /bin/mv -f prototypes.h.tmp prototypes.h
+
+clean:
+ /bin/rm -rf build *~ *.orig
+
+$(shell mkdir -p build)
+
+
+
+
diff --git a/humidity_sensors/app/awu.c b/humidity_sensors/app/awu.c
new file mode 100644
index 0000000..18cf1f8
--- /dev/null
+++ b/humidity_sensors/app/awu.c
@@ -0,0 +1,70 @@
+#include "project.h"
+
+/** Contains the different values to write in the APR register (used by AWU_Init function) */
+CONST uint8_t APR_Array[17] =
+ {
+ 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 61, 23, 23, 62
+ };
+
+/** Contains the different values to write in the TBR register (used by AWU_Init function) */
+CONST uint8_t TBR_Array[17] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 14, 15, 15
+ };
+
+
+FlagStatus AWU_GetFlagStatus(void)
+{
+ return((FlagStatus)(((uint8_t)(AWU->CSR & AWU_CSR_AWUF) == (uint8_t)0x00) ? RESET : SET));
+}
+
+
+INTERRUPT_HANDLER (AWU_IRQHandler, 1)
+{
+ AWU_GetFlagStatus();
+}
+
+
+void AWU_Init(AWU_Timebase_TypeDef AWU_TimeBase)
+{
+ /* Enable the AWU peripheral */
+ AWU->CSR |= AWU_CSR_AWUEN;
+
+ /* Set the TimeBase */
+ AWU->TBR &= (uint8_t)(~AWU_TBR_AWUTB);
+ AWU->TBR |= TBR_Array[(uint8_t)AWU_TimeBase];
+
+ /* Set the APR divider */
+ AWU->APR &= (uint8_t)(~AWU_APR_APR);
+ AWU->APR |= APR_Array[(uint8_t)AWU_TimeBase];
+}
+
+
+void AWU_LSICalibrationConfig(uint16_t lsifreqkhz)
+{
+ uint16_t A = 0x0;
+
+
+ /* Calculation of AWU calibration value */
+
+ A = (uint16_t)(lsifreqkhz >> 2U); /* Division by 4, keep integer part only */
+
+ if ((4U * A) >= ((lsifreqkhz - (4U * A)) * (1U + (2U * A))))
+ {
+ AWU->APR = (uint8_t)(A - 2U);
+ }
+ else
+ {
+ AWU->APR = (uint8_t)(A - 1U);
+ }
+}
+
+
+void awu_init(void)
+{
+
+ AWU_LSICalibrationConfig(128);
+ AWU_Init(AWU_TIMEBASE_1S);
+}
+
+
diff --git a/humidity_sensors/app/main.c b/humidity_sensors/app/main.c
index a94d681..d7f5908 100644
--- a/humidity_sensors/app/main.c
+++ b/humidity_sensors/app/main.c
@@ -10,9 +10,12 @@ main (void)
uart_init();
i2cb_init();
+ awu_init();
+
sht20_reset();
- //enableInterrupts ();
+
+ enableInterrupts ();
for (;;) {
printf ("$SNTHD,%s,%s\n", sht20_temp_s(), sht20_humid_s());
@@ -22,6 +25,6 @@ main (void)
sht20_reset();
}
- delay_ms (1000);
+ halt();
}
}
diff --git a/humidity_sensors/app/prototypes.h b/humidity_sensors/app/prototypes.h
index 35dbcd9..db8c949 100644
--- a/humidity_sensors/app/prototypes.h
+++ b/humidity_sensors/app/prototypes.h
@@ -1,30 +1,29 @@
/* 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);
+void delay(volatile u32 n);
+void delay_ms(volatile u32 n);
int putchar(int c);
/* uart.c */
-void uart_tx(uint8_t d);
-int uart_rx(uint8_t *d);
+void uart_tx(u8 d);
+int uart_rx(u8 *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);
+u8 i2cb_send(u8 wot);
+u8 i2cb_send_addr(u8 addr, u8 rnw);
+int i2cb_send_data(u8 d);
+u8 i2cb_read(u8 ack);
void i2cb_start(void);
void i2cb_stop(void);
-int i2cb_start_transaction(uint8_t a, uint8_t rnw);
+int i2cb_start_transaction(u8 a, u8 rnw);
void i2cb_reset(void);
void i2cb_init(void);
/* clock.c */
-uint32_t CLK_GetClockFreq(void);
+u32 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);
+u8 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);
@@ -33,3 +32,7 @@ void sht20_reset(void);
char *sht20_temp_s(void);
char *sht20_humid_s(void);
/* stm8s_it.c */
+/* awu.c */
+void AWU_Init(AWU_Timebase_TypeDef AWU_TimeBase);
+void AWU_LSICalibrationConfig(uint16_t lsifreqkhz);
+void awu_init(void);
diff --git a/humidity_sensors/app/stm8s_it.c b/humidity_sensors/app/stm8s_it.c
index 5a30096..864297c 100644
--- a/humidity_sensors/app/stm8s_it.c
+++ b/humidity_sensors/app/stm8s_it.c
@@ -92,6 +92,7 @@ INTERRUPT_HANDLER (TLI_IRQHandler, 0)
*/
}
+#if 0
/**
* @brief Auto Wake Up Interrupt routine.
* @param None
@@ -103,6 +104,7 @@ INTERRUPT_HANDLER (AWU_IRQHandler, 1)
it is recommended to set a breakpoint on the following instruction.
*/
}
+#endif
/**
* @brief Clock Controller Interrupt routine.
diff --git a/humidity_sensors/stm8flash b/humidity_sensors/stm8flash
-Subproject cdafc4638d714ed1a5250cac794b5b28e5cbfa0
+Subproject 34554cf495d274d575f3533ebfc28764064bd8f
diff --git a/tasmota-config/configure-humidifier b/tasmota-config/configure-humidifier
new file mode 100755
index 0000000..029c860
--- /dev/null
+++ b/tasmota-config/configure-humidifier
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+# Adapted from https://tasmota.github.io/docs/Rules/#simple-thermostat-example
+
+# Button give 30 mins of hot.
+
+# Low setpoint is var1
+# High setpoint is var2
+# Have water in var3
+
+# Timer1 is used as a WDT incase sensor fails
+#
+
+M=10.32.139.1
+
+
+set -x
+
+T=music_room_humidifier
+
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Backlog" -m "Rule1 1; Rule1 4; Rule2 1; Rule2 4; Rule3 1; Rule3 4"
+sleep 3
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Backlog" -m "TelePeriod 60; SetOption26 0; SetOption0 0; PowerOnState 0; switchmode2 1"
+sleep 3
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Backlog" -m "Setoption36 0; Setoption65 1; Setoption1 1; SensorRetain 1; PowerRetain 1"
+sleep 3
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Backlog" -m "SwitchMode1 0;SwitchMode2 1; SetOption63 1; LedMask 2"
+sleep 3
+
+
+
+## timer 1 turns off if we lose contact with sensor
+## publish a humid event on humidity data
+
+read -r -d '' R << EOF
+ ON system#boot DO Backlog RuleTimer1 70; var1 48; var2 53; ENDON
+ ON Rules#Timer=1 DO Backlog RuleTimer1 70; Power1 0 ENDON
+ ON tele-SI7021#humidity DO Backlog RuleTimer1 70; Event humid=%value% ENDON
+EOF
+R="$(echo $R)"
+
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Rule1" -m "${R}"
+sleep 5
+
+## publish setpoints on humidity data
+
+read -r -d '' R << EOF
+ ON Event#humid DO BackLog Publish2 stat/${T}/var1 %var1%; Publish2 stat/${T}/var2 %var2%; Publish2 stat/${T}/var3 %var3% ENDON
+ ON Switch2#state=0 DO BackLog var3 0; Power1 0 ENDON
+ ON Switch2#state=1 DO var3 1 ENDON
+EOF
+R="$(echo $R)"
+
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Rule2" -m "${R}"
+sleep 5
+
+##
+
+read -r -d '' R << EOF
+ ON Event#humid<%var1% DO Power1 %var3% ENDON
+ ON Event#humid>%var2% DO Power1 0 ENDON
+EOF
+R="$(echo $R)"
+
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Rule3" -m "${R}"
+sleep 5
+
+#
+
+mosquitto_pub -h "${M}" -t "cmnd/${T}/Restart" -m "1"
+
+
+exit 0
+