I have had limited success in that the code does detect one device at address0 (the INA219 has an actual address is 40 (7 bit) or $80 /write). If I remove this device, the program reports: no devices found, as expected. One more interesting aspect is that, if I plug in an eeprom, (specifically a 24LC02) and run the code the output is: NO I2C DEVICE FOUND.
ALSO, THE SCANNER BY BITFOGAV (MODIFIED FOR THE 24k22) ALSO REPORTS A device at address 0 FOR THE SAME IC.
If you can take a look at this, I would appreciate your thoughts.
THANKS
Lee
Code: Select all
' I2C ScannerII.BAS BASED ON CODE BY Gavin Wiggett (Bitfogav) et al
'TO FIND AND REPORT ALL I2C DEVICE ADDRESSES FOUND
' NOTE!!
' I2C Version : 1.3 7/11/20 JM / MUST BE PRESENT IN THE LIBRARY!!! AS A FUNCTION
'FROM THE I2C MODULE CALLED IsPresent(addr) IS USED HERE
' NOT TESTED WITH SWORDFISH-SE version BUT COMPILES OK ON SE 16 APR 2021
' I/O LIST ----------------------------------------------------------------
' software uart tx port PIN 28 LETS GET SDATA VIA PROGRAM CONNECTOR PIN 4 <<
' software uart rx port PIN 27 *not used here* VIA PROGRAM CONNECTOR PIN 5
' I2C_SCL = PORTC.3 ----> 18F24k22 pin 14 <<
' I2C_SDA = PORTC.4 ----> 18F24k22 pin 15 <<
' UART PARAMETERS ---------------------------------------------------------------
' OUTPUT IS VIA THE SUART AT 19200 N8&1 USING THE PROGRAMING CONNECTOR PIN 4
' THE SERIAL DATA IS TRUE SetMode(umTrue) [NOT INVERTED]
'*************************************************
'* memory usage: [PGM=1747 DATA=191 bytes] *
'*************************************************
Device = 18F24k22 'using Vdd = 3.3 or 5.0 volts
Clock = 64 'using 16 MHz x4
Config FOSC = HSHP '0010= HS oscillator (high power, >16 MHz)
Config PLLCFG = ON '1 = 4 x PLL always enabled, Oscillator multiplied by 4
#option DIGITALIO_INIT = true 'TNX JM
Include "convert.bas"
Include "utils.bas"
Include "SUART.bas"
Include "i2c.bas"
Include "system.bas"
Include "setdigitalio.bas"
'Include "LCD.bas"
'Include "i2ceeprom.bas"
Dim Devices As Byte
Dim addr As Byte
Dim addrs As Byte
'SetAllDigital()
'Software UART SET-UP - ports tx/rx use the programing connector clk & dta pins
'-----------------------------------------------------------------------------------
'SetMode(umInverted) ' software uart serial data is ISOLATED & INVERTED BY AN FET
SetMode(umTrue) ' software uart serial data is true via usb chip
SetBaudrate(sbr19200) ' software uart serial data rate is 19200 baud
SetTX(PORTB.7) ' software uart tx port PIN 28 LETS GET SDATA VIA PROGRAM CONNECTOR PIN 4
SetRX(PORTB.6) ' software uart rx port PIN 27 *not used here* VIA PROGRAM CONNECTOR PIN 5
DelayMS (8000) ' DELAY SO THE SERIAL PORT CAN BE CONNECTED
Devices = 0
UART.Write(" THIS COULD BE A HANDY TOOL FOR TROUBLE SHOOTING I2C ISSUES" ,13,10)
UART.Write(" THIS CODE IS BASED ON AN IDEA AND CODE BY BITFOGAV " ,13,10,10)
UART.Write(" Scanning for I2C Devices..", 13, 10)
I2C.Initialize(I2C_100_KHZ)
For addr = 0 To 126 Step 2
UART.Write(" SCANNED ADDRESS $", HexToStr(addr), 13, 10)
DelayMS (100)
addrs = addr '<<<<<<<<<<<< added to see if an address name confflict?
If IsPresent(addrs) Then
UART.Write(" FOUND I2C DEVICE @ $", HexToStr(addr), 13, 10, 10)
Devices = Devices + 1
EndIf
Next
UART.Write(" -------------------------------------------------------", 13, 10, 10)
If Devices <> 0 Then
UART.Write(" (",DecToStr(Devices), ") I2C device(s) found", 13, 10)
Else
UART.Write(" NO I2C devices found", 13, 10)
EndIf
End