Shop OBEX P1 Docs P2 Docs Learn Events
How to discover I2C device addresses — Parallax Forums

How to discover I2C device addresses

Does anyone have a code snippet or other means of discovering any I2C device's address?
I have a couple I2C displays and other things that I would like to interface, but don't know the proper I2C address.

Thanks in advance!

Comments

  • You could loop through all 128 addresses and see which ones generate and ACK.
  • @DaveJenson

    @JonnyMac has some code on github that scans for a range of addresses and lists what it finds in a matrix.

    https://github.com/parallaxinc/propeller/tree/master/libraries/community/p2/All/jm_i2c_devices

    At least that's how I read the code. It looks like the zip file has all the objects you need to run the code. I'm downloading it now to test it. It only prints the addresses though.

    However, there are a couple of URLs which do list I2c addresses. Below are a few I found with the "Is there a database of I2C addresses" google search:

    https://i2cdevices.org/addresses
    https://learn.adafruit.com/i2c-addresses/the-list

    Their list seems to terminate at 0x7F. Not sure why. They don't have the $A4 and $A5 addresses for my RV-3028-C7 RTC though.


  • Here's some code that will do it. The test program uses pins 28 and 29, and finds the EEPROM at $A0. Change the value of SCL to match the pin number you use for your test device. The driver requires that SDA be on the next higher pin.
  • JonnyMacJonnyMac Posts: 9,102
    edited 2020-12-30 22:42
    I've attached P1 and P2 versions of my I2C scanner. I tend to use PST, but if you want to use an ANSI/VT100-compatible terminal, set T_TYPE to T_ANSI and you'll get what you see in the attached images. The P1 is scanning the standard I2C bus and detect the EEPROM. The P2 has detected an I2C LCD on its test pins.
  • Wow! So much information on this Forum!
    Thanks!
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-12-30 23:46
    Tachyon and TAQOZ both have the lsi2c function which scans for acks from all the read adddresses and displays not just the device address but also takes a guess at the device function. This information is normally reported at reset but you can type lsi2c at any time.
    *** I2C ***                                                                                                                                
    $40 I/O                                                                                                                                    
    $A0 EE/RTC                                                                                                                                 
    $AE EE/RTC                                                                                                                                 
    $DE RTC  
    
    TAQOZ# lsi2c --- I2C DEVICES
      $36           P2D2 UB USB+SUPPORT  UUID:E09BAD5834DEE811A8D742B1A51F80DA                                                                 
      $A4           RV-3028 RTC                                                                                                                
      $C4           Si5351A CLOCK GEN ok
    
  • Tachyon and TAQOZ both have the lsi2c function which scans for acks from all the read adddresses and displays not just the device address but also takes a guess at the device function. This information is normally reported at reset but you can type lsi2c at any time.
    *** I2C ***                                                                                                                                
    $40 I/O                                                                                                                                    
    $A0 EE/RTC                                                                                                                                 
    $AE EE/RTC                                                                                                                                 
    $DE RTC  
    
    TAQOZ# lsi2c --- I2C DEVICES
      $36           P2D2 UB USB+SUPPORT  UUID:E09BAD5834DEE811A8D742B1A51F80DA                                                                 
      $A4           RV-3028 RTC                                                                                                                
      $C4           Si5351A CLOCK GEN ok
    

    Peter, I can't seem to get lsi2c to work on my P2 Edge in the Flexprop terminal that is started when selecting P2 ROM TAQOZ.

    lsi2c ???

    Is lsi2c part of some extended command set? Or is because there aren't any I2C devices currently connected?
  • TAQOZ in ROM tries to keep the most useful functions since it has to fit in 12k including the dictionary and some of the utility functions had to be left out including the I2C routines. But just load in TAQOZ RELOADED binary from my Dropbox or the SourceForge page. You can load it in with any P2 loader and optionally back it up to an SD card.
  • Francis, the command starts with an 'L' (as in 'list'), not 'I' (as in 'I2C').

    I2C is one of those acronyms that people use freely, while not knowing what it stands for (Inter-Integrated Circuit).
  • If it is not a number and it is not in the dictionary then you will get the ??? when in interactive mode. Use WORDS to list the words in the dictionary. Remember it had to fit into 12k and runs at RCFAST at around 25MHz but the usefulness of it is that you can use it to debug hardware even when nothing else works. Nonetheless it is very possible to program and extend even if you only had a serial terminal.
    There is nothing stopping you from taking a few seconds to load the TAQOZ binary into RAM, and if you have an SD card inserted, just tell it to backup to it with BU.
    -------------------------------------------------------------------------------                   
      Parallax P2  .:.:--TAQOZ--:.:.  V1.1--v33h         190219-1900                                  
    -------------------------------------------------------------------------------                   
    TAQOZ#  ---  ok                                                                                                                                                                 
    TAQOZ# lsi2c ???  ---  ok                                                                         
    TAQOZ# WORDS ---                                                                                  
    DUP OVER SWAP ROT -ROT DROP 3RD 4TH 2DROP 3DROP NIP 2SWAP 2DUP ?DUP AND                           
    ANDN OR XOR ROL ROR >> << SAR 2/ 2* 4/ 4* 8<< 16>> 8>> 9<< 9>> REV |< >|                          
    >N >B >9 BITS NOT = <> 0= 0<> 0< < U< > U> <= => WITHIN DUPC@ C@ W@ @ C+!                         
    C! C@++ W+! W! +! ! BIT! SET CLR SET? 1+ 1- 2+ 2- 4+ + - UM* * W* / U/                            
    U// // */ UM// C++ C-- W++ W-- ++ -- RND GETRND SQRT SETDACS ~ ~~ W~ W~~                          
    C~ C~~ L>S >W L>W W>B W>L B>W B>L MINS MAXS MIN MAX ABS -NEGATE ?NEGATE                           
    NEGATE ON TRUE -1 FALSE OFF GOTO IF ELSE THEN BEGIN UNTIL AGAIN WHILE REPEAT                      
    SWITCH CASE@ CASE= CASE> BREAK CASE ADO DO LOOP +LOOP FOR NEXT ?NEXT I                            
    J LEAVE IC@ I+ BOUNDS H L T F R HIGH LOW FLOAT PIN@ WRPIN WXPIN WYPIN RDPIN                       
    RQPIN AKPIN WAITPIN WRACK PIN @PIN ns PW PULSE PULSES HILO DUTY NCO HZ                            
    KHZ MHZ MUTE BLINK PWM SAW BIT BAUD TXD RXD TXDAT WAITX WAITCNT REBOOT                            
    RESET 0EXIT EXIT NOP CALL JUMP >R R> >L L> !SP DEPTH COG@ COG! LUT@ LUT!                          
    COGID COGINIT COGSTOP NEWCOG COGATN POLLATN SETEDG POLLEDG KEY WKEY KEY!                          
    CON NONE COM CONKEY CONEMIT SEROUT EMIT EMITS CRLF CR CLS SPACE SPACES                            
    RAM DUMP: DUMP DUMPW DUMPL DUMPA DUMPAW QD QW DEBUG lsio COG LUT KB MB                            
    M . PRINT .AS .AS" .DECL .DEC4 HOLD #> <# # #S <D> U. .DEC .BIN .H .B .BYTE                       
    .W .WORD .L .LONG .ADDR PRINT$ LEN$ " ." CTYPE ?EXIT DATA? ERASE FILL CMOVE                       
    <CMOVE s ms us CNT@ LAP LAP@ .LAP .ms HEX DEC BIN .S WORDS @WORDS GET$                            
    SEARCH $># @DATA HERE @HERE @CODES uemit ukey char delim names TASK REG                           
    @WORD SPIN | || , [W] ["] NULL$ $! $= ASM FORGET CREATE$ CREATE VAR pub                           
    pri pre : ; [ ] ' := ==! ALIGN DATCON ALLOT org bytes words longs byte                            
    word long res [C] GRAB NFA' CPA CFA \ --- ( { } IFNDEF IFDEF TAQOZ TERM                           
    AUTO SPIRD SPIRDL SPIWB SPICE SPIWC SPIWW SPIWM SPIWL SPIPINS SPIRX SPITXE                        
    SPITX WAIT CLKDIV RCSLOW HUBSET WP WE CLKHZ ERROR SFPINS SF? SFWE SFINS                           
    SFWD SFSID SFJID SFER4 SFER32 SFER64 SFERASE SFWRPG BACKUP RESTORE SFRDS                          
    SFWRS SFC@ SFW@ SF@ SF .SF SDBUF sdpins MOUNT DIR !SD !SX SD? CMD ACMD                            
    cid SDWR SDRDS SDWRS FLUSH FOPEN FLOAD FGET FREAD FWRITE SECTOR SDRD SDRDS                        
    SDADR SD@ SD! SDC@ SDC! SDW@ SD @FAT @BOOT @ROOT fat END  432 ok                                  
    TAQOZ#
    
  • In TAQOZ, how do I change which pins are connected to devices?
    For instance I2C. Which pins does this look at and how to change it?
    Is there a comprehensive list of which pins TAQOZ default uses for devices?
    Thanks!
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2021-01-15 05:26
    DaveJenson wrote: »
    In TAQOZ, how do I change which pins are connected to devices?
    For instance I2C. Which pins does this look at and how to change it?
    Is there a comprehensive list of which pins TAQOZ default uses for devices?
    Thanks!

    Hi Dave, I almost missed your post. If you call I2CPINS ( scl sda -- ) it will also setup the pins with stiff 1K5 soft pullups as soon as you start to talk to the bus. You can go as fast as the fastest chip can go (well over 3000 kHZ) or slow right down for those really really old 100kHz chips too by using I2C.KHZ ( khz -- )

    You don't external pullups but most of the time they are fairly weak 10k pullups anyway so it doesn't matter if you already have them connected.

    Use lsi2c to discover and list the I2C devices on the bus.
Sign In or Register to comment.