Skip to content

Commit

Permalink
drivers/sensor: sht3xd: implement single shot mode
Browse files Browse the repository at this point in the history
For now there is only periodic data acquisition mode implemented.
This mode is quite power consuming. Based on datasheet in idle
state in periodic data acquisition mode SHT3X consumes 45uA but
in single shot mode 0.2uA. For many applications where power
consumption has to be kept as low as possible single shot mode
is the only choice. Tester on custom board NRF52832 + SHT31-DIS.

Signed-off-by: Michał Oleszczyk <[email protected]>
  • Loading branch information
oleszczyk authored and MaureenHelm committed Sep 18, 2019
1 parent 1593de9 commit da4d00e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
16 changes: 16 additions & 0 deletions drivers/sensor/sht3xd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ config SHT3XD_REPEATABILITY_HIGH

endchoice

choice
prompt "Measurement mode"
default SHT3XD_PERIODIC_MODE

config SHT3XD_SINGLE_SHOT_MODE
bool "single shot"

config SHT3XD_PERIODIC_MODE
bool "periodic data acquisition"

endchoice

if SHT3XD_PERIODIC_MODE

choice
prompt "Measurements per second"
default SHT3XD_MPS_1
Expand All @@ -93,4 +107,6 @@ config SHT3XD_MPS_10

endchoice

endif # SHT3XD_PERIODIC_MODE

endif # SHT3XD
27 changes: 26 additions & 1 deletion drivers/sensor/sht3xd/sht3xd.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
LOG_MODULE_REGISTER(SHT3XD);

#ifdef CONFIG_SHT3XD_SINGLE_SHOT_MODE
static const u16_t measure_cmd[3] = {
0x2400, 0x240B, 0x2416
};
#endif
#ifdef CONFIG_SHT3XD_PERIODIC_MODE
static const u16_t measure_cmd[5][3] = {
{ 0x202F, 0x2024, 0x2032 },
{ 0x212D, 0x2126, 0x2130 },
{ 0x222B, 0x2220, 0x2236 },
{ 0x2329, 0x2322, 0x2334 },
{ 0x272A, 0x2721, 0x2737 }
};
#endif

static const int measure_wait[3] = {
4000, 6000, 15000
Expand Down Expand Up @@ -85,6 +92,22 @@ static int sht3xd_sample_fetch(struct device *dev, enum sensor_channel chan)

__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);

#ifdef CONFIG_SHT3XD_SINGLE_SHOT_MODE
/* start single shot measurement */
if (sht3xd_write_command(dev,
measure_cmd[SHT3XD_REPEATABILITY_IDX])
< 0) {
LOG_DBG("Failed to set single shot measurement mode!");
return -EIO;
}
k_sleep(K_MSEC(measure_wait[SHT3XD_REPEATABILITY_IDX] / USEC_PER_MSEC));

if (i2c_read(i2c, rx_buf, sizeof(rx_buf), address) < 0) {
LOG_DBG("Failed to read data sample!");
return -EIO;
}
#endif
#ifdef CONFIG_SHT3XD_PERIODIC_MODE
u8_t tx_buf[2] = {
SHT3XD_CMD_FETCH >> 8,
SHT3XD_CMD_FETCH & 0xFF
Expand All @@ -95,6 +118,7 @@ static int sht3xd_sample_fetch(struct device *dev, enum sensor_channel chan)
LOG_DBG("Failed to read data sample!");
return -EIO;
}
#endif

t_sample = (rx_buf[0] << 8) | rx_buf[1];
if (sht3xd_compute_crc(t_sample) != rx_buf[2]) {
Expand Down Expand Up @@ -179,6 +203,7 @@ static int sht3xd_init(struct device *dev)

k_busy_wait(SHT3XD_CLEAR_STATUS_WAIT_USEC);

#ifdef CONFIG_SHT3XD_PERIODIC_MODE
/* set periodic measurement mode */
if (sht3xd_write_command(dev,
measure_cmd[SHT3XD_MPS_IDX][SHT3XD_REPEATABILITY_IDX])
Expand All @@ -188,7 +213,7 @@ static int sht3xd_init(struct device *dev)
}

k_busy_wait(measure_wait[SHT3XD_REPEATABILITY_IDX]);

#endif
#ifdef CONFIG_SHT3XD_TRIGGER
if (sht3xd_init_interrupt(dev) < 0) {
LOG_DBG("Failed to initialize interrupt");
Expand Down

0 comments on commit da4d00e

Please sign in to comment.