Page 1 of 1

SPI slave problem

Posted: Wed Dec 04, 2019 6:38 pm
by dsiganos
Hi, trying to run the following script, renders the openmv H7 hardware unusable.

Code: Select all

print('First line')
from pyb import SPI
spi = SPI(2, SPI.SLAVE, polarity=0)
ch = bytearray('ab')
res = spi.send_recv(ch, timeout=1)
print(res, ch)
When I try to run the script above, the hardware "appears" to hang.
I don't even see the first line printed.
The only way to get back to interacting with the board is to power cycle it.

If I remove the spi.send_recv call then the hardware does not freeze and the script runs to completion.

I have nothing connected to the SPI pins.

Any ideas?

Re: SPI slave problem

Posted: Wed Dec 04, 2019 7:29 pm
by kwagyeman
Yeah, what happens is that in slave mode the board needs to receive a clock from the SPI master. Without that clock the MCU will wait on the SPI receive call to return. The timeout should causes the system to throw an exception however if no clock was being received.

Um, I don't recommend using the OpenMV Cam as a SPI or I2C slave. I tried this long ago and determined it to be a bad path to go down and a waste of your time. Make it a master device.

...

The hanging part implies there's another bug however. Did you run this in the IDE? Does the USB disconnect after running the script?

Re: SPI slave problem

Posted: Wed Dec 04, 2019 7:44 pm
by dsiganos
Yes, I run this from the IDE.
The IDE appears to hangs for 10-20 seconds and then eventually it comes back and shows the device as disconnected (I imagine something times out).

Re: SPI slave problem

Posted: Wed Dec 04, 2019 8:00 pm
by kwagyeman
Yeah, that's the IDE timing out. Okay, there's probably a bug in the SLAVE mode. It should just throw an exception on board timeout. Instead it's getting stuck in an infinite loop.

Re: SPI slave problem

Posted: Wed Dec 04, 2019 8:00 pm
by kwagyeman
Sorry about this... Whenever we update MP (like to version 1.11 with our latest firmware) various things break.

Re: SPI slave problem

Posted: Thu Dec 05, 2019 6:00 am
by iabdalkader
Hi, there's an SPI example with the Arduino as the master device and the OpenMV Cam as the slave in Examples->00-Arduino/arduino_spi_slave.py that has been tested and know to work with the latest firmware.