I2C Address Sniffer

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

I2C Address Sniffer

Postby medelec35 » Wed Apr 11, 2018 12:46 pm

I have developed a basic I2C address sniffer.
I’m running mine on 12F1840 but it can very easily be adapted for other microcontrollers.
Data is sent via UART (baud = 9600) in software mode so does not clash with hardware I2C.
TX and RX are set on the same pins to reduce pin count.
If I2C hardware is connected, then the correct addresses should be detected.
for Example, I have Adafuit 8x8 matrix based on HT16K33.
With no address selection pads bridged, Ran the sniffer and got:
Address none Bridged.png
Address none Bridged.png (25.11 KiB) Viewed 2328 times

Bridged A0, then Re-ran and got:
Address  A1 Bridged.png
Address A1 Bridged.png (25.32 KiB) Viewed 2328 times

Lower address is used for writing to IC2 and the Next higher address is for Reading of I2C.
You can have multiple I2C devices connected for all of them to be detected.

Note: If I2C is not connected or there is a hardware issue of I2C or wiring you will get:
Hardware Error.png
Hardware Error.png (21.14 KiB) Viewed 2335 times
Attachments
IC2 Address Sniffer.fcfx
(18.05 KiB) Downloaded 117 times
These users thanked the author medelec35 for the post (total 7):
LeighM (Wed Apr 11, 2018 12:51 pm) • jgu1 (Wed Apr 11, 2018 3:27 pm) • Steve (Wed Apr 11, 2018 5:26 pm) • kersing (Wed Apr 11, 2018 8:18 pm) • Benj (Thu Apr 12, 2018 10:12 am) • EtsDriver (Mon Apr 16, 2018 4:57 pm) • stefan.erni (Thu Apr 19, 2018 7:22 pm)
Rating: 36.84%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

mnf
Valued Contributor
Valued Contributor
Posts: 558
Joined: Wed May 31, 2017 11:57 am
Has thanked: 54 times
Been thanked: 313 times
Contact:

Re: I2C Address Sniffer

Postby mnf » Tue Apr 24, 2018 6:25 pm

Tried adapting this for Arduino....

My current project involves an Arduino 'chain' communicating over i2c. This works very well (my test setup has 3 arduinos and a 'master' controlling them) using the i2c_slave component.

However, i2c sniffer doesn't detect them (indeed it 'locks' up) - this is also true for the i2c scanner with the Arduino IDE..

So I wondered what response (if any) should a slave controller give to be recognized by a 'sniffer' program such as this?

Martin

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: I2C Address Sniffer

Postby medelec35 » Tue Apr 24, 2018 7:27 pm

Hi Martin (cool name!),
I would imagine the Sniffer and Scanner work in a similar way.
I only know about the PIC side of things.
When you adapted to the Arduino, did you still have the interrupt enabled?
If so was there any message to Serial Monitor?

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

mnf
Valued Contributor
Valued Contributor
Posts: 558
Joined: Wed May 31, 2017 11:57 am
Has thanked: 54 times
Been thanked: 313 times
Contact:

Re: I2C Address Sniffer

Postby mnf » Wed Apr 25, 2018 4:27 pm

An Arduino version...

Calling it "Arduino Sniffer" maybe sounds a bit dubious...

Arduino i2c Address Sniffer.fcfx
(13.07 KiB) Downloaded 78 times


Seems to work OK for 'genuine' i2c parts (RTC etc) - but no joy with the Arduino Nanos running i2c slave programs.

Correction - it does eventually report the address of the slave devices - just takes a very long time to do so (minutes rather than seconds) - seems there is a (long) timeout at play somewhere?

Note that transmitting messages to the slaves works nicely!

Sorry - the interrupt routine had to go :-)

Martin (2)

A strange (Windows) bug - got two Arduinos connected with the same COM port... Weird and not very successful.
Last edited by mnf on Wed Apr 25, 2018 4:36 pm, edited 1 time in total.
These users thanked the author mnf for the post:
medelec35 (Wed Apr 25, 2018 4:35 pm)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: I2C Address Sniffer

Postby medelec35 » Wed Apr 25, 2018 4:34 pm

Thank you for your version. :)
mnf wrote:Calling it "Arduino Sniffer" maybe sounds a bit dubious...
:lol:
mnf wrote:Sorry - the interrupt routine had to go :-)

Don't know about non pic version but for pic the interrupt is Essential.
If there is an issue with I2C then the pic will just halt so will not be able to send a message warning about a hardware issue or to inform you of being finished.
Perhaps you could try on Arduino with no I2C hardware connected?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

mnf
Valued Contributor
Valued Contributor
Posts: 558
Joined: Wed May 31, 2017 11:57 am
Has thanked: 54 times
Been thanked: 313 times
Contact:

Re: I2C Address Sniffer

Postby mnf » Wed Apr 25, 2018 4:58 pm

Thanks -

Seems to work ok when the Nanos are reset - there is a brief window of opportunity before the body of the receiver program (a slightly modified Matrix example) runs but after the i2c_slave library has initialised.. I feel I should probably be responding with a ACK (or NAK)? rather than waiting for the (in this case) non-existent data bytes.
But - how to determine if you are just being 'sniffed' or are receiving a command...

It's early days - I'm wanting the Nanos in the chain to process the message from the preceding 'node' and then pass the (modified) data to the next node (by becoming an i2c master - it all sounds very Zen). The final link the chain will pass back to the first Arduino (the master) which will then issue a global message to get all the nodes to update simultaneously! In theory it is possible..

Losing the interrupt means that thing's just grind to a halt if the i2c fails - some more info output might help? "Now sniffing address"....

Martin
These users thanked the author mnf for the post:
medelec35 (Thu Dec 20, 2018 9:09 am)
Rating: 5.26%