diff options
author | root <root@ka-ata-killa.ourano.james.local> | 2021-02-17 18:33:49 +0000 |
---|---|---|
committer | root <root@ka-ata-killa.ourano.james.local> | 2021-02-17 18:33:49 +0000 |
commit | c994c3323ee1b0d19faa86ebe26a01d566b86eaa (patch) | |
tree | 6dd2b0ee878938f13b5cc2429f9092ad659680ad /humidity_sensors/app/sht20.c | |
parent | 1f91e592c0b97dc315335417f323d31ca028782a (diff) | |
download | heating-c994c3323ee1b0d19faa86ebe26a01d566b86eaa.tar.gz heating-c994c3323ee1b0d19faa86ebe26a01d566b86eaa.tar.bz2 heating-c994c3323ee1b0d19faa86ebe26a01d566b86eaa.zip |
stm8 humidity sensor
Diffstat (limited to 'humidity_sensors/app/sht20.c')
-rw-r--r-- | humidity_sensors/app/sht20.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/humidity_sensors/app/sht20.c b/humidity_sensors/app/sht20.c index d6d648b..5d6acb7 100644 --- a/humidity_sensors/app/sht20.c +++ b/humidity_sensors/app/sht20.c @@ -11,6 +11,13 @@ #define SOFT_RESET 0xFE +#define MAX_RESOLUTION ((u8) 0x00) +#define BATTERY_LOW ((u8) 0x40) +#define RESERVED_MASK ((u8) 0x38) +#define ENABLE_HEATER ((u8) 0x04) +#define DISABLE_OTP_RELOAD ((u8) 0x02) + + void sht20_reset (void) { @@ -119,3 +126,27 @@ sht20_humid_s (void) return ret; } + +void sht20_setup (void) +{ + uint8_t u; + + i2cb_start_transaction (SHT20_ADDRESS, I2C_WRITE); + i2cb_send_data (READ_USER_REG); + i2cb_start_transaction (SHT20_ADDRESS, I2C_READ); + u = i2cb_read (0); + i2cb_stop(); + + + u &= RESERVED_MASK; + u |= MAX_RESOLUTION | DISABLE_OTP_RELOAD; + + // FWIW - it appears to be impossible to turn off the heater + // with either a reset or write, perhaps a fake chip? + u &= ~ ENABLE_HEATER; + + i2cb_start_transaction (SHT20_ADDRESS, I2C_WRITE); + i2cb_send_data (WRITE_USER_REG); + i2cb_send_data (u); + i2cb_stop(); +} |