SPI slave problem

Discussion related to "under the hood" OpenMV topics.
dsiganos
Posts: 3
Joined: Wed Dec 04, 2019 6:29 pm

SPI slave problem

Postby dsiganos » Wed Dec 04, 2019 6:38 pm

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?
User avatar
kwagyeman
Posts: 3503
Joined: Sun May 24, 2015 2:10 pm

Re: SPI slave problem

Postby kwagyeman » Wed Dec 04, 2019 7:29 pm

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?
Nyamekye,
dsiganos
Posts: 3
Joined: Wed Dec 04, 2019 6:29 pm

Re: SPI slave problem

Postby dsiganos » Wed Dec 04, 2019 7:44 pm

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).
User avatar
kwagyeman
Posts: 3503
Joined: Sun May 24, 2015 2:10 pm

Re: SPI slave problem

Postby kwagyeman » Wed Dec 04, 2019 8:00 pm

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.
Nyamekye,
User avatar
kwagyeman
Posts: 3503
Joined: Sun May 24, 2015 2:10 pm

Re: SPI slave problem

Postby kwagyeman » Wed Dec 04, 2019 8:00 pm

Sorry about this... Whenever we update MP (like to version 1.11 with our latest firmware) various things break.
Nyamekye,
User avatar
iabdalkader
Posts: 1026
Joined: Sun May 24, 2015 3:53 pm

Re: SPI slave problem

Postby iabdalkader » Thu Dec 05, 2019 6:00 am

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.

Return to “Technical Discussion”

Who is online

Users browsing this forum: MSN [Bot] and 2 guests