Page 1 of 1

I2C Address Sniffer

Posted: Wed Apr 11, 2018 12:46 pm
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

Re: I2C Address Sniffer

Posted: Tue Apr 24, 2018 6:25 pm
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?


Re: I2C Address Sniffer

Posted: Tue Apr 24, 2018 7:27 pm
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?


Re: I2C Address Sniffer

Posted: Wed Apr 25, 2018 4:27 pm
by mnf
An Arduino version...

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

Re: I2C Address Sniffer

Posted: Wed Apr 25, 2018 4:34 pm
by medelec35
Thank you for your version. :)
mnf wrote: Calling it "Arduino Sniffer" maybe sounds a bit dubious...
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?

Re: I2C Address Sniffer

Posted: Wed Apr 25, 2018 4:58 pm
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"....