Skip to content

Commit

Permalink
Appease CLang
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Aug 25, 2023
1 parent 1de49c9 commit 2733666
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Adafruit_AM2320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,27 @@ uint32_t Adafruit_AM2320::readRegister32(uint8_t reg) {
// wake up
for (int i = 0; i < 3; i++) {
written = i2c_dev->write(buffer, 1);
if(written) break;
if (written)
break;
delay(100); // 50-70 lead to 2 errors each time
}
if (!written) return 0xFFFFFFFF; // no ACK!
delay(10); // wait 10 ms
if (!written)
return 0xFFFFFFFF; // no ACK!
delay(10); // wait 10 ms

// send a command to read register
buffer[0] = AM2320_CMD_READREG;
buffer[1] = reg;
buffer[2] = 4; // 4 bytes
for (int i = 0; i < 3; i++) {
written = i2c_dev->write(buffer, 3);
if(written) break;
if (written)
break;
delay(5);
}
if (!written) return 0xFFFFFFFF; // read not acknowledged!
delay(2); // wait 2 ms
if (!written)
return 0xFFFFFFFF; // read not acknowledged!
delay(2); // wait 2 ms

// 2 bytes preamble, 4 bytes data, 2 bytes CRC
i2c_dev->read(buffer, 8);
Expand Down

0 comments on commit 2733666

Please sign in to comment.