Skip to content

Commit 4ec2129

Browse files
committed
Added function to test a single address
1 parent 7185efe commit 4ec2129

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

README.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ unsigned char ucMap[16];
4040

4141
I2CScan(ucMap);
4242

43+
To detect if a single address is active, use I2CTest(addr).
44+
4345
For reading and writing data to the I2C device, use the following functions:
4446

4547
I2CRead(uint8_t u8Address, uint8_t *pu8Data, int iLength);

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=BitBang_I2C
2-
version=1.0.0
2+
version=1.1.0
33
author=Larry Bank <[email protected]>
44
maintainer=Larry Bank <[email protected]>
55
sentence=Bit-bang the I2C protocol on any 2 GPIO pins on any system.

src/BitBang_I2C.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,21 @@ void I2CInit(int iSDA_Pin, int iSCL_Pin, int32_t iClock)
493493
else iDelay = 1000000 / iClock;
494494
} /* i2cInit() */
495495
//
496+
// Test a specific I2C address to see if a device responds
497+
// returns 0 for no response, 1 for a response
498+
//
499+
uint8_t I2CTest(uint8_t addr)
500+
{
501+
uint8_t response = 0;
502+
503+
if (i2cBegin(addr, 0)) // try to write to the given address
504+
{
505+
response = 1;
506+
}
507+
i2cEnd();
508+
return response;
509+
} /* I2CTest() */
510+
//
496511
// Scans for I2C devices on the bus
497512
// returns a bitmap of devices which are present (128 bits = 16 bytes, LSB first)
498513
// A set bit indicates that a device responded at that address

src/BitBang_I2C.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ int I2CWrite(uint8_t iAddr, uint8_t *pData, int iLen);
3636
//
3737
// Scans for I2C devices on the bus
3838
// returns a bitmap of devices which are present (128 bits = 16 bytes, LSB first)
39+
//
40+
// Test if an address responds
41+
// returns 0 if no response, 1 if it responds
42+
//
43+
uint8_t I2CTest(uint8_t addr);
44+
3945
// A set bit indicates that a device responded at that address
4046
//
4147
void I2CScan(uint8_t *pMap);

0 commit comments

Comments
 (0)