I2C scanner

Acexbe
Posts: 6
Joined: Tue Aug 28, 2018 11:57 am

I2C scanner

Unread post by Acexbe »

Hello,
This snipped of code lists all connected devices to the I2C bus.
The bus can manage 128 devices.
The first seven are reserved, so 120 are available.
This code is intended for I2C devices with a 7 bit address.
However, newer devices have a 10 bit address.
As the ezsbc1 seems to handle 10 bit addresses, you can increase the address range (tested and working).

I2CINIT(100000)
I2CTIME(10)
FOR address=8 TO 120

I2CWR(address,0x00,"",0)
IF I2CBUSY(address)=0 THEN
PRINT hex$(address)
ENDIF

NEXT address

END
Acexbe
Posts: 6
Joined: Tue Aug 28, 2018 11:57 am

Re: I2C scanner version 2

Unread post by Acexbe »

This is an update that shows the 7 bit base slave address with its 8 bit read and write part.

I2CINIT(100000)
I2CTIME(10)

FOR address=0x08 TO 0xFF

I2CWR(address,0x00,"",0)

IF I2CBUSY(address)=0 THEN

base=(address LSR 1)
PRINT "slave address: 0x",HEX$(base);
bit0=(address & 1)

IF bit0=1 THEN
direction$=" read "
ELSE
direction$=" write"
ENDIF

PRINT direction$," address: 0x",HEX$(address)

IF tmp=base THEN
PRINT"---------------------------------------"
ENDIF

tmp=base

ENDIF

NEXT address
PRINT"End"
Post Reply