Fix AM2302 sensor

This commit is contained in:
Xose Pérez
2018-04-23 14:11:08 +02:00
parent e834867ec6
commit 427aebe8a7
2 changed files with 4 additions and 1 deletions

View File

@@ -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);

View File

@@ -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];