From 427aebe8a756ce57fcdab9dc7f5b8bda7fa5d5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 23 Apr 2018 14:11:08 +0200 Subject: [PATCH] Fix AM2302 sensor --- code/espurna/config/prototypes.h | 1 + code/espurna/sensors/AM2320Sensor.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/code/espurna/config/prototypes.h b/code/espurna/config/prototypes.h index ba8e0723..a9316d74 100644 --- a/code/espurna/config/prototypes.h +++ b/code/espurna/config/prototypes.h @@ -77,6 +77,7 @@ bool i2cGetLock(unsigned char address); bool i2cReleaseLock(unsigned char address); unsigned char i2cFindAndLock(size_t size, unsigned char * addresses); +void i2c_wakeup(uint8_t address); uint8_t i2c_write_buffer(uint8_t address, uint8_t * buffer, size_t len); uint8_t i2c_write_uint8(uint8_t address, uint8_t value); uint8_t i2c_write_uint8(uint8_t address, uint8_t reg, uint8_t value); diff --git a/code/espurna/sensors/AM2320Sensor.h b/code/espurna/sensors/AM2320Sensor.h index 656be183..5acea0b6 100644 --- a/code/espurna/sensors/AM2320Sensor.h +++ b/code/espurna/sensors/AM2320Sensor.h @@ -120,7 +120,9 @@ class AM2320Sensor : public I2CSensor { */ void _read() { + i2c_wakeup(); + // waiting time of at least 800 μs, the maximum 3000 μs delayMicroseconds(800); // just to be on safe side @@ -128,7 +130,7 @@ class AM2320Sensor : public I2CSensor { // 4 = number of bytes to read if (i2c_write_uint8(_address, AM2320_I2C_READ_REGISTER_DATA, 0x00, 4) != I2C_TRANS_SUCCESS) { _error = SENSOR_ERROR_TIMEOUT; - return false; + return; } unsigned char _buffer[8];