[riot-notifications] [RIOT-OS/RIOT] drivers/dht: Bugfixes (#11876)

MichelRottleuthner notifications at github.com
Wed Jul 24 11:38:46 CEST 2019


MichelRottleuthner requested changes on this pull request.

Tested with tests/driver_dht and examples/saul on samr21-xpro using dht11 and dht22. The fixes work as described in general, but please fix the checksum as described below.

>  #define PULSE_WIDTH_THRESHOLD       (40U)
+/* If an expected pulse is not detected within 1000µs, something is wrong */
+#define TIMEOUT                     (1000U)
+/* The DHT sensor cannot measure more than once a second */
+#define DATA_HOLD_TIME              (US_PER_SEC)
+/* The start signal by pulling data low for at least 18ms and than up for

s/than/then

> +            _reset(dev);
+            return DHT_TIMEOUT;
+        }
+
+        if (_read(&csum, dev->params.pin, 8)) {
+            _reset(dev);
+            return DHT_TIMEOUT;
+        }
+
+        /* Bring device back to defined state - so we can trigger the next reading
+         * by pulling the data pin low again */
+        _reset(dev);
+
+        /* validate the checksum */
+        sum = (raw_temp >> 8) + (raw_temp & 0xff) + (raw_hum >> 8) + (raw_hum & 0xff);
+        if ((sum != csum) || (csum == 0)) {

The checksum verify won't work this way. According to the datasheet only the lowest 8 bit are used for the checksum. So either add `& 0xFF` or change back the type of `sum` to uint8_t.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11876#pullrequestreview-265892870
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190724/9b595373/attachment.htm>


More information about the notifications mailing list