I2C Bus Sniffing

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

I2C Bus Sniffing

Post by devnull » Fri Nov 17, 2017 12:20 pm

Has anybody done anything on this that could help me from reinventing the wheel ??

I can do this with bus-pirate but I would like to be able to do it with uPython.

I guess the only way would be bit-banging using an interrupt pin ?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: I2C Bus Sniffing

Post by deshipu » Fri Nov 17, 2017 1:34 pm

What are you trying to do exactly?

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: I2C Bus Sniffing

Post by devnull » Fri Nov 17, 2017 1:50 pm

Listen to a battery talking to it's parent device.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: I2C Bus Sniffing

Post by deshipu » Fri Nov 17, 2017 7:29 pm

To collect raw clocked data, you can use the SPI peripheral, but you will still need to find some way to get the start and stop conditions somehow — probably with a pin interrupt, as you wrote. There is one more problem — you won't know which of the devices is pulling the line at any given moment — for that, your board would have to act as a man-in-the-middle, having each device connected to a separate set of pins and repeating what they do to the other device.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: I2C Bus Sniffing

Post by dhylands » Fri Nov 17, 2017 9:12 pm

Using the SPI interface will only work if a device doesn't stretch the clock.

You probably want to create a new I2C-sniffer module based on the software I2C code, or add a mode to the software I2C module to allow it to be a sniffer.

To be a sniffer the SDA and SCL signals will always be inputs and would never be driven.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: I2C Bus Sniffing

Post by deshipu » Fri Nov 17, 2017 11:40 pm

Why won't SPI work with clock stretching? The clock line will remain low until the new bit is sent, whether it's stretched or not, so I think it should work?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: I2C Bus Sniffing

Post by dhylands » Fri Nov 17, 2017 11:49 pm

You're right. I wasn't thinking about this in the right context. I think that the issue would be detecting start & stop bits and dealing with the ack/nack.

User avatar
devnull
Posts: 473
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall
Contact:

Re: I2C Bus Sniffing

Post by devnull » Sat Nov 18, 2017 1:05 pm

Thanks but writing a module is beyond my capabilities, I was hoping to be able to do this within Python.

Post Reply