<< return to Pixycam.com

I2C Clock Stretching

Does the Pixy support clock Stretching? I am still trying to get the pixy working with the STM32F3Discovery board without success. When I have the pixy working with an Arduino Mega I notice that there is a delay in the clock cycles after sending the address with the R/W bit and before the clock when it starts reading the data byte. I am wondering if this is just a delay controlled by the Arduino or if the Pixy is holding the clock low as part of a clock stretching technique. Either way, when I hook-up the STM32 board there is no delay in the clock. On the STM32 board I sporadically read all zeros for the first byte and I cannot figure out why. I always read all zeros at the beginning of the frame which means my software can never sync up with the pixy. Today I am planning on re-writing my code back down to the basic I2C protocol blocks (start, read, stop, etc) so I can manually add a delay similar to what I see on the arduino in hopes that this will fix the problem.

If anyone can shed some light on why my first byte is coming in as all zeros I would be very grateful. Also if there is a specific I2C protocol event (i.e. restart, etc) that I need between the end of the “address/read” command and the beginning of a read operation I would like to know that as well.
Here are some screen shots of what I am seeing on the scope. First one is the signals with the Arduino attached and the second is with the STM32F3Discovery attached.

Thank you all for your time.

Regards,
Brent

Hello Brent,
Pixy should not be stretching the clock. Are you using firmware version 2.0.8?

Regarding the stream of zeros, since Pixy is an I2C slave, Pixy will return zeros when it’s addressed if and only if there are no detected objects (no data).

Edward

Thanks for the reply Edward.

I am not getting all zeros. Just the first byte of the first word of the frame. I have posted a sample output from my controller in the link below.

http://www.cmucam.org/boards/9/topics/5518

You can see that it appears that I am reading in an object but the sync word is coming in as 0x0055 instead of 0xaa55.

Any ideas?

Oh,…and my pixy firmware version is: 0.1.43 (I have never updated my firmware on the pixy…will the updated firmware help?)

Hello Brent,
I don’t have a clear answer for what’s happening. You should definitely use the latest firmware though!

Do you have an Arduino? It might help to look at how the Arduino and Pixy talk over I2C. Just ideas.

Edward

Ed, I have a copy of the I2C communication with an Arduino Mega attached in the original post and that is what made me think something was wrong with the communication since the arduino had a pause between reading bytes and the STM32F3 did not.

As it turns out I found my mistake and there was nothing wrong with the communication over I2C with or without the pause. I had switched the bytes when I was constructing the 16-bit word (big endian instead of little endian). I was using an array to hold the 2 bytes and I put index “1” where I should have put index “0” and vice versa.

It wasn’t until I had given up on I2C and started coding an SPI interface when I realized my simple mistake in swapping the bytes.

Regardless, Thank you for responding to my posts. It is comforting to know that when you run in to issues there is a community that is willing to help.

Brent