Page 1 of 1

i2c bus reinitialization

Posted: Mon Oct 24, 2016 8:12 pm
by Gromit
Hi!

I have a setup where I use the pyboard to read data from a slave device via i2c. The pyboard is set up as the master and waits for the slave to toggle a GPIO pin, at which point it initiates a transfer of 4 bytes using i2c.recv(). This works fine in general but I do see occasional errors that I think are due to high bus capacitances (causing the SDA/SCL timing to fall out of i2c spec).

I've gotten 3 different error codes so far and the weird thing is that the i2c object needs to be re-initialized most times.

--------------------
OSError 5:
This is a slave-side issue. I can see the pyboard trying to ping the slave with its address, but not receiving an acknowledgement. If I fix the slave and do an i2c.recv(), then things work normally as expected.

OSError 16 and 110:
If i2c.recv() is called after receiving this error, nothing happens on the bus lines (they stay at VCC, monitored using an oscilloscope). I just keep getting OSError 110s until the i2c object is re-initialized:

i2c.deinit()
pyb.delay(500)
i2c.init(I2C.MASTER, baudrate=7000)

After that I can i2c.recv() and it works fine...until the next error. Also, OSError 110 is apparently a 'timeout' error, but there doesn't seem to be any communication to be 'timing out of' since nothing seems to be physically happening on the bus lines.
--------------------

At the end of the day it's not a huge issue since I try-catch these exceptions to reset things, but is this normal? Having to re-initialize things constantly? I'm running the i2c bus super slow, so maybe that affects things?

Thanks!

Re: i2c bus reinitialization

Posted: Tue Oct 25, 2016 6:47 am
by pythoncoder
It sounds as if you're using the bus in an unorthodox way if you're running it 'super slow' and still have capacitance problems. Have you considered providing additional pullup resistors (subject to checking the chip's drive capability)? The Pyboard's pullups are 4.7K.