Skip to content

Commit 2f7c23a

Browse files
clawpiladyada
andcommitted
Add software reset in begin() for clean initialization
Write SW_RESET bit in CONTROL register (0xFA) during init to force a full power-on reset. Clears any stale SMUX/measurement state from previous runs. Polls I2C bus until chip responds after reset. Fixes intermittent messed-up state on boot. Co-authored-by: ladyada <limor@ladyada.net>
1 parent 10fac2f commit 2f7c23a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Adafruit_AS7343.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ bool Adafruit_AS7343::_init() {
7272
return false;
7373
}
7474

75+
// Software reset — forces a full power-on reset to clear any stale state
76+
{
77+
uint8_t buf[2] = {AS7343_CONTROL, 0x08}; // bit 3 = SW_RESET
78+
i2c_dev->write(buf, 2);
79+
delay(200); // Wait for reset to complete
80+
81+
// Chip reboots with REG_BANK=0, PON=0 — poll until I2C responds
82+
for (uint8_t retries = 0; retries < 20; retries++) {
83+
if (i2c_dev->detected()) {
84+
break;
85+
}
86+
delay(50);
87+
}
88+
}
89+
7590
// Power on
7691
if (!powerOn(true)) {
7792
return false;

0 commit comments

Comments
 (0)