I2C scanner

I2C scanner

Postby Acexbe » Mon Oct 08, 2018 1:44 pm

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 2:57 pm

Re: I2C scanner version 2

Postby Acexbe » Mon Nov 19, 2018 3:48 pm

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"
Acexbe
 
Posts: 6
Joined: Tue Aug 28, 2018 2:57 pm


Return to EzSBC1

Who is online

Users browsing this forum: No registered users and 1 guest

cron