I2C SCANNER

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
LEEDNH
Posts: 42
Joined: Fri Feb 03, 2017 8:44 pm

I2C SCANNER

Post by LEEDNH » Sun Apr 18, 2021 10:40 pm

I'm back again. I am trying to scan for I2C devices using the function"IsPresent(addr)" from the I2C module. Looking at the "IsPresent(addr)"it seems to do the exact function of verifying that an I2C device exists in the pic's hardware @ addr.

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


Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C SCANNER

Post by Jerry Messina » Mon Apr 19, 2021 12:30 pm

Let's start with the basics...

- you do have pull up resistors on SCL and SDA, correct? (10K or less)
- I'm sure you just added it later, but you don't need your 'addrs' variable
- the I2C module uses full 8-bit addresses, so they always include the R/W bit

If the 24LC02 is the only device on the bus, it should respond to addr = $A0 (assuming you have the A2-A0 pins strapped low).

The INA219 is a little different. The I2C addr for that should be addr = $80 (assuming you have A1 and A0 strapped low).
But, in section 8.5.5 of the TI datasheet it states "The INA219 offers compatibility with both I2C and SMBus interfaces".
Most SMBus devices also include support for the I2C General Call address, and section 8.5.6.2 talks about General Call Reset.

There are a few addresses reserved in the I2C spec, and address 0 is one of them... it's the General Call address.
So, the INA219 should show up at two addresses... 00 and 80.

I'd get things working with the 24LC02 all by itself first, just in case there's something funny with the INA219.

Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C SCANNER

Post by Jerry Messina » Mon Apr 19, 2021 1:46 pm

I just noticed this. If you want to scan the entire address range, the 'for' loop needs to be:

Code: Select all

    for addr = 0 to 127
        if (I2C2.IsPresent(addr<<1)) then
		// device found
	else
		// not found
	 endif
That scans all even address bytes from 0 to 254 ($FE), which covers the 7-bit addresses 0 to 127.
Stopping at 126 isn't going to catch addr $A0

and if you wanted to scan all addresses, both read and write:

Code: Select all

#option I2C_PROBE_RD_ADDR = true
#include "I2C.bas"

   for addr = 0 to 255
        if (I2C2.IsPresent(addr)) then
		// device found
	else
		// not found
	endif
    next
That'll normally get you two hits per device.
I usually only scan the write address since I've never seen a "read-only" device, and I've seen some devices act weird when you scan the read address.

EDIT: the examples here were edited, so some of Lee's comments that follow might not make sense...
Last edited by Jerry Messina on Tue Apr 20, 2021 12:20 am, edited 2 times in total.

LEEDNH
Posts: 42
Joined: Fri Feb 03, 2017 8:44 pm

Re: I2C SCANNER

Post by LEEDNH » Mon Apr 19, 2021 9:49 pm

I was wondering why the address range was from 0 to 126 as I have used the I2C successfully in the past and always shifted left for the read / write bit, (that's what happens to a copy cat). I had tried the 128 to 254 loop and got a "hit" on every address. I suspected that zero might represent a "special" address, but an internet search yielded nothing helpful...

I will implement your changes and get rid of the ina219 from China via Amazon. I have a "real" INA219 via a slow dog cart from Texas.
Thanks Jerry
Lee

Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C SCANNER

Post by Jerry Messina » Mon Apr 19, 2021 11:04 pm

The INA219 may be ok... once you change the loop to scan more addresses you should see it show up at 0 and $80 (128).
We weren't scanning far enough at first to see it in both places.

LEEDNH
Posts: 42
Joined: Fri Feb 03, 2017 8:44 pm

Re: I2C SCANNER

Post by LEEDNH » Mon Apr 19, 2021 11:52 pm

It works! But, it behaves as if it were in an infinite loop, ignoring the for-next. I noticed the continuous operation when I used 8 bit addresses while trouble shooting... Here are the results (for a scan from $80 to $FE) and code I added to escape from the tendency for infinite repetition ....

Scanning for I2C Devices..
SCANNED ADDRESS $80
FOUND I2C DEVICE @ $80 <<<<<<<<FOUND THE INA219 !

SCANNED ADDRESS $82
SCANNED ADDRESS $84
.......................
SCANNED ADDRESS $A0
FOUND I2C DEVICE @ $A0 <<<<<<<<PROVIDES THE EXPECTED MEMORY IMAGES FOR THE 24XX02 EEPROM

SCANNED ADDRESS $A2
FOUND I2C DEVICE @ $A2

SCANNED ADDRESS $A4
FOUND I2C DEVICE @ $A4

SCANNED ADDRESS $A6
FOUND I2C DEVICE @ $A6

SCANNED ADDRESS $A8
FOUND I2C DEVICE @ $A8

SCANNED ADDRESS $AA
FOUND I2C DEVICE @ $AA

SCANNED ADDRESS $AC
FOUND I2C DEVICE @ $AC

SCANNED ADDRESS $AE
FOUND I2C DEVICE @ $AE

SCANNED ADDRESS $B0
.....................
SCANNED ADDRESS $FA
SCANNED ADDRESS $FC
SCANNED ADDRESS $FE
-------------------------------------------------------

(9) I2C device(s) found


<<<<<<<<<< Added to overcome the problem of ignoring the for-next....

For addr = 128 To 254 Step 2 'comment out one of these (excludes the 0-126 addresses)

UART.Write(" SCANNED ADDRESS $", HexToStr(addr), 13, 10)

DelayMS (50)

If (I2C.IsPresent(addr)) Then

UART.Write(" FOUND I2C DEVICE @ $", HexToStr(addr), 13, 10, 10)
Devices = Devices + 1

EndIf

If addr = 254 GoTo escape ' ADDED TO ESCAPE THE FOR - NEXT AFTER ONE COMPLETE CYCLE <<<<<<<<<<

Next

escape: ' EXIT THE FOR - NEXT LOOP <<<<<<<<<<<<<<<<
UART.Write

Once again Thanks Jerry

Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C SCANNER

Post by Jerry Messina » Tue Apr 20, 2021 12:02 am

That's what I get for not trying something before posting it.

The for loop
For addr = 128 To 254 Step 2
won't work very well since 'addr' is a byte. On the last loop it'll try to increment it:
addr = 254 + 2 = 256, which gets truncated to 0 since it's a byte

I think the best/clearest code is probably

Code: Select all

// scan all 'write' addresses
for addr = 0 to 127
	if I2C.IsPresent(addr << 1) then
	    // found
	else
	   // not found
	endif
next
I'll fix the posting where this came from so it doesn't crop up again.

LEEDNH
Posts: 42
Joined: Fri Feb 03, 2017 8:44 pm

Re: I2C SCANNER

Post by LEEDNH » Tue Apr 20, 2021 4:24 am

Hi Jerry
The reason I started messing with the scanner was because I was having trouble with an I2C INA219 I/V/P MONITORING DEVICE. It would free a pin now used as an analog port to an INA240 HI SIDE ANALOG CURRENT MONITOR. Applying this device has really grown into something I never expected. The ina219 works fine with the SF I2C at address $80 << from $40. Two of the internal registers respond with appropriate values while the third is "out to lunch" which is what I get for not using parts from a "real" distributor....
Yet another question....
The statement: if I2C.IsPresent(addr << 1) then Should it be if I2C.IsPresent(<<addr) then ?
There isn't much as far as examples for ( >>var) or (<<var) shifts that I have been able to find.
I have used:
for x = 0 to 2
>>var
next
to shift right 3x. I am assuming zeros fill the three displaced bits on the left.....
Thanks again
Lee

LEEDNH
Posts: 42
Joined: Fri Feb 03, 2017 8:44 pm

Re: I2C SCANNER

Post by LEEDNH » Tue Apr 20, 2021 4:48 am

Hi jerry

I am confused about the shift instructions.

addr = addr>>3 is this statement okay in SF. shift addr right 3x
A statement like addr = addr>>3 seemed to give compile errors when I tried it.

Your if I2C.IsPresent(addr << 1) then compiles fine.....
You may have fixed another mistake I have been making....

>>addr this seems to compile but I'm not sure if it means shift right 1x

Lee

LEEDNH
Posts: 42
Joined: Fri Feb 03, 2017 8:44 pm

Re: I2C SCANNER

Post by LEEDNH » Tue Apr 20, 2021 6:41 am

THE CODE MAY BE READY FOR A TEST DRIVE (OF THE BETA KIND)......

THE PROGRAMMING INTERFACE PINS 2, 3, & 4 ARE USED FOR POWER AND SERIAL OUT AT 19200 8N&1.
THE OUTPUT I GOT FROM MY BOARD IS AS FOLLOWS (SOME ADDRESSES REMOVED TO MAKE IT MORE COMPACT):
-----------------------------------------------------------------------------------------------------------------

THIS COULD BE A HANDY TOOL FOR TROUBLE SHOOTING I2C ISSUES
Version 1.0 dtd 04/19/2021 / 18F24k22 / by LEEDNH please try it out
BASED ON AN IDEA / CODE BY BITFOGAV AND MUCH HELP FROM JERRY MESSINA

Scanning for I2C Devices......................
SCANNED I2C ADDRESS $0
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $0
which is the I2C SF write address @ $0

SCANNED I2C ADDRESS $1
SCANNED I2C ADDRESS $2
.............................

SCANNED I2C ADDRESS $3F
SCANNED I2C ADDRESS $40
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $40
which is the I2C SF write address @ $80

SCANNED I2C ADDRESS $41
SCANNED I2C ADDRESS $42
...............................

SCANNED I2C ADDRESS $4F
SCANNED I2C ADDRESS $50
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $50
which is the I2C SF write address @ $A0

SCANNED I2C ADDRESS $51
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $51
which is the I2C SF write address @ $A2

SCANNED I2C ADDRESS $52
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $52
which is the I2C SF write address @ $A4

SCANNED I2C ADDRESS $53
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $53
which is the I2C SF write address @ $A6

SCANNED I2C ADDRESS $54
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $54
which is the I2C SF write address @ $A8

SCANNED I2C ADDRESS $55
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $55
which is the I2C SF write address @ $AA

SCANNED I2C ADDRESS $56
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $56
which is the I2C SF write address @ $AC

SCANNED I2C ADDRESS $57
FOUND AN ACTIVE I2C DEVICE ADDRESS @ $57
which is the I2C SF write address @ $AE

SCANNED I2C ADDRESS $58
SCANNED I2C ADDRESS $59
..............................

SCANNED I2C ADDRESS $7E
SCANNED I2C ADDRESS $7F
-------------------------------------------------------

(10) ACTIVE I2C device address(es) found


CODE FOLLOWS:

Code: Select all

         
 ' I2C ScannerII.BAS      BASED ON AN IDEA/CODE BY (Bitfogav) et al: TO FIND AND  
                                     'REPORT ALL I2C DEVICE ADDRESSES CONNECTED
                                     
' THIS INTERFACES TO THE PIC VIA THE PROGRAMING PINS:  PIN 2 = 5V,  PIN 3 = GND                                     
                                                  'AND PIN 4 = SERIAL DATA OUT 
' IMPORTANT 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                     
                                                                           
' 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 <<                    

' SUART 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=1933  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

 Include "convert.bas"
 Include "utils.bas" 
 Include "SUART.bas"
 Include "i2c.bas"  
 Include "system.bas"
 Include "setdigitalio.bas"
   
   Dim Devices As Byte
   Dim addr 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 ENABLED & connected
     
    Devices = 0
    UART.Write("   THIS COULD BE A HANDY TOOL FOR TROUBLE SHOOTING I2C ISSUES" ,13,10) 
    UART.Write("   Version 1.0  dtd 04/20/2021 / 18F24k22 / by LEEDNH please try it out " ,13,10)
    UART.Write("   BASED ON AN IDEA / CODE BY BITFOGAV AND MUCH HELP FROM JERRY MESSINA" ,13,10,10)
    
    UART.Write("   Scanning for I2C Devices......................", 13, 10)
   
    I2C.Initialize(I2C_100_KHZ)
  
    For addr = 0 To 127
   
    UART.Write("   SCANNED I2C ADDRESS $", HexToStr(addr), 13, 10)
   
    DelayMS (50) 'so the human can watch the output
    
    If I2C.IsPresent(addr << 1)  Then
   
     UART.Write("    FOUND AN ACTIVE I2C DEVICE ADDRESS @ $", HexToStr(addr), 13, 10)
     UART.Write("     which is the I2C SF write address @ $", HexToStr(addr << 1), 13, 10, 10)
     Devices = Devices + 1
   
    EndIf
   
    Next  
  
    UART.Write("  -------------------------------------------------------", 13, 10, 10)
   
    If Devices <> 0 Then
    UART.Write("   (",DecToStr(Devices), ")  ACTIVE I2C device address(es) found", 13, 10)
    Else
    UART.Write("   NO ACTIVE I2C device addresses found", 13, 10)
    EndIf
   
    End                

Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C SCANNER

Post by Jerry Messina » Tue Apr 20, 2021 10:50 am

For the left-shift (<<) and right-shift (>>) operators, the syntax is:
variable_to_shift SHIFT_OP number_of_times_to_shift

For example:
A = B >> 1
means : shift 'B' right 1 time and assign the result to 'A'
The variable 'B' itself is not modified as a result of doing the shift.

If you use it as a parameter in a subroutine call like 'IsPresent(addr<< 1)',
it means take the variable 'addr', shift it left by 1, and use that shifted value as the parameter in the call.

So, the statements '<<addr' or '>>var' used by themselves are both invalid syntax.
BUT, you have to watch out. Lets say you have:

Code: Select all

a = i >> 1
<< i
That actually compiles ok and gets interpreted to mean:

Code: Select all

a = (i >> 1)  << i

Now, as far as the results in your scan:
Most I2C serial EEPROMS have a few hdw addresses pins (typ labelled A0, A1. A2, etc) allowing you to address multiple chips on the same bus.
This varies with device and mfg, so you have to check the datasheet for the exact part you're using.

For the Microchip 24LC02, the datasheet shows pins A2, A1, and A0, BUT if you read carefully they're not used and are 'don't cares', so you end up
with a 7-bit address = '1010 xxx'. That means it'll respond to any address from 'A0' to 'AF', and you can only have one of these devices on the bus
since the '1010' portion is fixed.

So, it looks like you're getting the right result.

LEEDNH
Posts: 42
Joined: Fri Feb 03, 2017 8:44 pm

Re: I2C SCANNER

Post by LEEDNH » Wed Apr 21, 2021 12:53 am

HI JERRY,
Yes we are getting good results. Due to your guidance. Left on my own, I would be going in circles of ever increasing radii.
I do very much appreciate your help!

I had tried the shift instruction as Z = Z >> 3 TAKE Z SHIFT IT 3 X RIGHT AND STICK IT BACK INTO Z (KIND OF LIKE IN C) BUT I GOT AN ERROR ON COMPILE. THEN IN YOUR REPLY TO THE I2C SCANNER with IT DAWNED ON ME THAT (addr<<1) was a valid syntax... I was gobsmacked, astonished, surprised even.... I had done the same thing and the compiler said error... The compiler hates me because of all the sloppy & incorrect code that I feed it.... But I would choose it again over the others!

A COUPLE OF QUICK QUESTIONS IF I MAY?
---------------------------------------------------
IS Z = Z >> 3 VALID OR DOES IT NEED TO BE Y = Z >> 3 ?

AND DO #option DIGITALIO_INIT = true AND SetAllDigital() ACCOMPLISH THE SAME RESULT?

LOOKS LIKE TREE CUTTING WEATHER HERE IN NORTHERN NEW ENGLAND THIS SATURDAY BUT RAIN ALL DAY SUNDAY....
BEST REGARDS & THANKS AGAIN
LEE

Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C SCANNER

Post by Jerry Messina » Wed Apr 21, 2021 12:46 pm

IS Z = Z >> 3 VALID
Yes, it's valid. The following compiles fine for me:

Code: Select all

dim Z as byte

Z = Z >> 3
Maybe there was something else it was really complaining about?

DO #option DIGITALIO_INIT = true AND SetAllDigital() ACCOMPLISH THE SAME RESULT?
If you look at the last page of the library file SetDigitalIO.bas, you'll see the following:

Code: Select all

//
//--------------------------------------------------------------------------
// module init
//--------------------------------------------------------------------------
//
#if (DIGITALIO_INIT)
SetAllDigital()
#endif
The #option DIGITALIO_INIT is set false at the beginning of that file, so the default is to skip over the code.
If you set the #option true before including the file then it will automatically add the call to SetAllDigital() to the startup section of your program, and it runs before the main portion of your code starts.

It has the same effect as just adding a call to SetAllDigital() in your code, with one difference... when the call occurs.
Module initializers (the code at the end, outside of any subs or functions in the file) will run before the code in your main program file, and
they run in the order you 'include' them.

If you add

Code: Select all

#option DIGITALIO_INIT = true
include "setdigitalio.bas"
before any other 'includes' it'll be one of the first things to run.

Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C SCANNER

Post by Jerry Messina » Wed Apr 21, 2021 1:02 pm

I had done the same thing and the compiler said error... The compiler hates me because of all the sloppy & incorrect code that I feed it.... But I would choose it again over the others!
Here's a tip - when you get compilation errors they're listed in the results window "last to first".
Scroll down to the bottom of the window and fix them working back to the top of the list.

Many times fixing one will fix later ones that follow.

Post Reply