Skip to content

Commit 7af5523

Browse files
mooserykartben
authored andcommitted
driver: sensor: aosong,dht: fix sensor protocol broken since change #83192
A recent change 9eeb60c improperly removed a critical line in the driver. This commit replaces that line and moves an irq_lock to above any pin value manipulation since the timing is sensitive with the DHT protocol. This should also fix the timing issue 9eeb60c attempted to fix. Signed-off-by: John Shelton <moosery@gmail.com>
1 parent 1fb86e1 commit 7af5523

File tree

1 file changed

+12
-7
lines changed
  • drivers/sensor/aosong/dht

1 file changed

+12
-7
lines changed

drivers/sensor/aosong/dht/dht.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,26 @@ static int dht_sample_fetch(const struct device *dev,
6767
uint8_t buf[5];
6868
unsigned int i, j;
6969

70+
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
71+
7072
#if defined(CONFIG_DHT_LOCK_IRQS)
71-
int lock;
73+
/* Get the lock before any pin interaction since irq_lock has a */
74+
/* potential of causing delays itself. */
75+
int lock = irq_lock();
7276
#endif
7377

74-
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
75-
7678
/* assert to send start signal */
7779
gpio_pin_set_dt(&cfg->dio_gpio, true);
7880

79-
#if defined(CONFIG_DHT_LOCK_IRQS)
80-
lock = irq_lock();
81-
#endif
82-
8381
k_busy_wait(DHT_START_SIGNAL_DURATION);
8482

83+
/* set the state back to logic LOW (voltage HIGH) so that the */
84+
/* subsequent call to dht_measure_signal duration waits for the */
85+
/* DHT sensor to set it back to HIGH (voltage LOW). */
86+
/* Failure to do this would cause that subsequent call to */
87+
/* return immediately. */
88+
gpio_pin_set_dt(&cfg->dio_gpio, false);
89+
8590
/* switch to DIR_IN to read sensor signals */
8691
gpio_pin_configure_dt(&cfg->dio_gpio, GPIO_INPUT);
8792

0 commit comments

Comments
 (0)