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

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

I2C Address Sniffer

Post by medelec35 »

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
(25.11 KiB) Downloaded 4018 times
Bridged A0, then Re-ran and got:
Address A1 Bridged.png
(25.32 KiB) Downloaded 4018 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
(21.14 KiB) Downloaded 4025 times
Attachments
IC2 Address Sniffer.fcfx
(18.05 KiB) Downloaded 348 times
Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: I2C Address Sniffer

Post by mnf »

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: I2C Address Sniffer

Post by medelec35 »

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

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: I2C Address Sniffer

Post by mnf »

An Arduino version...

Calling it "Arduino Sniffer" maybe sounds a bit dubious...
Arduino i2c Address Sniffer.fcfx
(13.07 KiB) Downloaded 308 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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: I2C Address Sniffer

Post by medelec35 »

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

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: I2C Address Sniffer

Post by mnf »

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

Post Reply