SPI Slave Error: no attribute '_put_short_timeout'

I’m trying to use the OpenMV as an SPI slave device (using rpc), but I’m getting an error,

AttributeError: 'rpc_spi_slave' object has no attribute '_put_short_timeout'

A basic code to demonstrate the problem is here:

import image, math, pyb, sensor, rpc, struct, time

# Camera Setup

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 1000)

# Link Setup

interface = rpc.rpc_spi_slave()
dat_buf = struct.pack("<b", 0)
interface.put_bytes(dat_buf, timeout_ms = 200)

It crashes on put_bytes every time.

Note that I’ve used this same construct with I2C with the only needed change is from spi to i2c for the interface definition.

Full error output here:

Traceback (most recent call last):
  File "<stdin>", line 42, in <module>
  File "rpc.py", line 602, in put_bytes
AttributeError: 'rpc_spi_slave' object has no attribute '_put_short_timeout'
OpenMV v4.5.0; MicroPython v1.20-omv-r8; OPENMV4-STM32H743

There’s an issue with the library I need to debug. It’s tracked here: SPI Slave Error: no attribute '_put_short_timeout'

Please avoid using it for right now.

Thanks for the quick reply, as always.

Is there another SPI option? Other posts caution against writing my own interface. Or does the “Arduino” example, with the interrupt callback, work well?

Ultimately, I’m using the library to pass April Tag info (for a course in robotics). I just queue up the tags and send to the master robot. I’ve gotten both UART and I2C working with rpc, but I’d like to throw SPI at the students, as well.

Oh, also, the link you provided just comes back to this post. Did you link the right page?

Ah! Good catch: RPC Library SPI bus transfer is not working · Issue #1926 · openmv/openmv · GitHub

So, there’s something wrong with SPI control. The code was not touched but broke due to firmware updates. So, I need to hunt down what’s wrong. SPI master mode doesn’t work either.

Unfortunately, I’m not at home with all my equipment right now so I cannot debug the issue currently. However, I should be able to take a look after December 6th.

I know SPI master mode doesn’t work. The error you mentioned is different though. SPI slave mode may work if the missing attribute is fixed. Let me try a fix really quick.

Yeah, so, what you are doing doesn’t work… you shouldn’t call put_bytes until the link is up.

This is unrelated to the SPI master mode not working currently. You should be able to get SPI slave mode working if it’s still operational by using the RPC calls first before calling put_bytes.

self._put_short_timeout
self._get_short_timeout

Are defined only after getting the first command.

I think I what you’re saying, however…

…I’m not really using the rpc library in the way it was designed: For example, with the i2c interface, I’m not making remote function calls, per se. I just use put_bytes on the OpenMV to load up a buffer and then I use regular calls from the master to get data (eg, requestBytes()), mostly so I could walk students through how an I2C transaction works. Since the interrupt for a ST signal on the I2C bus is buried so deep in uPython, co-opting the rpc library was the easiest solution.

It’s working fine for I2C…I might just try to make my own SPI interface from the example. I’m just sending april tag data, so it’s hardly a lot of data.

Just copy the RPC SPI Master/Slave code:

Yeah, that works, of course.

Thanks for looking into it.