i2c clock line staying low acting as i2c slave

Discussion related to "under the hood" OpenMV topics.
dennisma
Posts: 2
Joined: Thu May 10, 2018 12:38 pm

i2c clock line staying low acting as i2c slave

Postby dennisma » Thu May 10, 2018 1:15 pm

I have an OpenMV acting as a slave device. It isn't actually doing anything but returning test data. It works great when I hook it up to an Arduino Uno which acts as the master. The problem is trying to get it to work with an old NXT lego brick (in RobotC).

The problem is it will return data on the first request from the NXT and then it appears the OpenMV holds the scl line low for 5 second. It then works again for one request and then holds the line low for 5 seconds again...and again...

First... here is the code on the OpenMV side (note I did the deinit() based on a post on this forum for another problem... didn't help)

Code: Select all

from pyb import I2C

def initI2C():
    return I2C(2, I2C.SLAVE,addr=0x14//2)
    
bus = initI2C()
bus.deinit() # Fully reset I2C device...
bus = initI2C()

print("Starting...")

data = bytearray(1)  # create a buffer
while(True):
    try:
        bus.recv(data,timeout=10000)       # receive 3 bytes, writing them into data
        print (data)
        bus.send("19191919")    

    except OSError as error:
        print(error)
        pass

The print out in the serial console is:

Code: Select all

bytearray(b'B')
[Errno 110] ETIMEDOUT
[Errno 5] EIO
bytearray(b'B')
[Errno 110] ETIMEDOUT
[Errno 5] EIO
[Errno 5] EIO
'B' (0x42)is what the NXT is sending to the OpenMV camera... so it does go through and receive it but then the clock is being held low by the OpenMV for 5 seconds.

Below is a screen shot from the logic analyzer. As you can see the clock is held low for 5 seconds almost exactly and it will run like this all day. (I've confirmed it is the OpenMV holding it low by yanking out the wire).

Just FYI... The clock and data line are being pulled high by 82K resistors per the NXT specs. It works well if I make the Arduino the slave (the arduino just works... I rarely have an i2c problem with it).
Screenshot 2018-05-10 13.10.05.png
Screenshot 2018-05-10 13.10.05.png (74.3 KiB) Viewed 445 times
dennisma
Posts: 2
Joined: Thu May 10, 2018 12:38 pm

Re: i2c clock line staying low acting as i2c slave

Postby dennisma » Thu May 10, 2018 1:43 pm

As a side note... if I put a 5 second delay in after every i2c call on the NXT side this thing never has any errors. It's like there is some sort of issue calling the OpenMV more than once every 5 seconds. The thing is... I didn't see this issue at all using an arduino as the master and the OpenMV as the slave (nor do I see this problem if I use an NXT as the master and the Arduino as a slave).

If anyone has any ideas what might be wrong send them my way. Thanks.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: i2c clock line staying low acting as i2c slave

Postby kwagyeman » Thu May 10, 2018 1:59 pm

Hi, when you have the OpenMV Cam as an I2C slave it kinda needs to have the result ready it's supposed to return ready to go before the master polls it. Otherwise, the camera shouldn't respond and should instead work on generating the next result to hold until someone asks for it. Given you want up to date computer vision responses I don't know how to make the OpenMV Cam as a I2C or SPI slave useful since it had to kinda wait and be ready to respond instead of doing work. Only async serial makes sense.

Anyway, let me take a look at your code. Also, note, we use MP's PYB module for IO. If you'd like to see this all inproved send us some example scripts and code fixes via PRs on GitHub and we'll merge into the release for the OpenMV Cam.
Nyamekye,
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: i2c clock line staying low acting as i2c slave

Postby kwagyeman » Thu May 10, 2018 2:01 pm

Okay, please see the Pixy Emulation Example scripts for I2C control. The code in there works. It's under examples -> Pixy emulation. In particular, you have to disable interrupts and whatnot.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests