Announcement

Collapse
No announcement yet.

I2C Scanner

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I2C Scanner

    Hello,
    Has anyone written an I2C Scanner for TCA9548A?

    Regards....

  • #2
    I have written a I2C scanner program that you can use.

    Code:
    DEFINE DEBUG_REG PORTC
    DEFINE DEBUG_BIT 6
    DEFINE DEBUG_BAUD 38400
    DEFINE DEBUG_MODE 0
    
    ADDRESSLO VAR BYTE
    ADDRESSHI VAR BYTE
    PARTADD VAR BYTE
    VALUE VAR BYTE
    
    '********************************************************************
    LOOP1: 'MAIN OPERATING LOOP
    '********************************************************************
    repeat
        DEBUG 27,"[H" 'HOME CURSOR
    debug 27,"[2J" 'CLEAR SCREEN
    DEBUG "    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F",10,13
    DEBUG "     |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |",10,13
    ADDRESSLO = $00
    ADDRESSHI = $00
    WHILE ADDRESSHI < $F0 'between $70 and $00
    DEBUG HEX2 ADDRESSHI,"--"
    ADDRESSLO = 00
    WHILE ADDRESSLO < $10 'between $0f and $00
    PARTADD = ADDRESSHI 'take UPPER 3 BITS
    PARTADD = PARTADD + ADDRESSLO 'add LOWER 4 BITS
    ' PARTADD = PARTADD << 1 '1 shift left for r/w bit
    I2CREAD SDA,SCL,PARTADD,[VALUE],NOACK
    ' DEBUG HEX2 PARTADD >> 1," " 'PRINT ADDRESS IF ACKNOWLAGED
    DEBUG HEX2 PARTADD," " 'PRINT ADDRESS IF ACKNOWLAGED
    GOTO NEXTADDLO
    NOACK: DEBUG " + " 'CLEAR ADDRESS IF NOT ACKNOWLAGED
    NEXTADDLO: ADDRESSLO = ADDRESSLO + 1
    WEND
    DEBUG 10,13,10,13
    ADDRESSHI = ADDRESSHI + $10
    WEND
    DEBUG 10,13
    PAUSE 1000
    
    UNTIL COWSCOMEHOME 'BACK FOR MORE...........
    '*********************************************************************
    END  
    '*********************************************************************
    Dave Purola,
    N8NTA
    EN82fn

    Comment


    • #3
      Hi Dave,

      Thanks for the response...

      When Compiling:
      Bad Expression (30)
      Bad Expression (43)
      i2creasd SDA,SCL,PARTADD,[VALUE],NOACK

      I am not able to attach anything.

      I have PBP GOLD 3.0.10.4
      MicroCode Studio 5.0.0.5

      Comment


      • #4
        you need to define which port the SDA line and SCL line are on. Don't forget the TRIS register. Also COWSCOMEHOME is a bit that needs to be defined...

        I have NO idea what processor you are using.......
        Dave Purola,
        N8NTA
        EN82fn

        Comment


        • #5
          It is for PIC16F873.

          SDA PORTC.4
          SCL PORTC.3
          UNTIL COWSCOMEHOME 'BACK FOR MORE........... Is this where the loop is to continue checking the TCA9548?

          Comment


          • #6
            The code only checks the address of the I2C devices on the bus. It does NOT check the state of the ex pander bits... That's up to you... Set all the outputs to 255 and then read the status...
            Dave Purola,
            N8NTA
            EN82fn

            Comment

            Working...
            X