Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4bca971

Browse files
committedJan 5, 2024
fixup i2c scanner
1 parent ab670a9 commit 4bca971

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed
 

‎io_utils.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,37 @@ uint16_t scani2c(bool pinswap = false){
6060
Wire.beginTransmission(address);
6161
int res = Wire.endTransmission();
6262

63-
// * Output 0 .. success
64-
// * 1 .. length to long for buffer
65-
// * 2 .. address send, NACK received
66-
// * 3 .. data send, NACK received
67-
// * 4 .. other twi error (lost bus arbitration, bus error, ..)
68-
63+
// https://www.arduino.cc/reference/en/language/functions/communication/wire/endtransmission/
64+
// endTransmission() returns:
65+
// 0: success.
66+
// 1: data too long to fit in transmit buffer.
67+
// 2: received NACK on transmit of address.
68+
// 3: received NACK on transmit of data.
69+
// 4: other error.
70+
// 5: timeout
71+
6972
if (res == 0)
7073
{
7174
Logger.print("[I2C] Device found - ADDR: 0x");
72-
if (address<16)
75+
if (address<16){
7376
Logger.print("0x");
7477
Logger.print(address,HEX); // 7 bit
7578
Logger.print(" 0x");
7679
Logger.print(2*address,HEX); // 8bit
7780
Logger.println("");
81+
}
7882
nDevices++;
7983
}
80-
else if(res!=2 && res !=255)
81-
{
82-
Logger.println("[ERROR]:" + (String)res);
83-
Logger.print("Unknown error ADDR: 0x");
84-
if (address<16)
85-
Logger.print("0");
86-
Logger.print(address,HEX);
84+
else if(res!=2 && res !=255){
85+
Logger.print("[ERROR]: code: " + (String)res);
86+
Logger.print(" ADDR: 0x");
87+
if (address<16){
88+
Logger.print("0x");
89+
Logger.print(address,HEX); // 7 bit
90+
Logger.print(" 0x");
91+
Logger.print(2*address,HEX); // 8bit
8792
Logger.println("");
93+
}
8894
}
8995
}
9096
if (nDevices == 0)

0 commit comments

Comments
 (0)
Please sign in to comment.