Hello there again!
We are using SPI to communicate with another microcontroller. The Camera is the spi-slave and the microcontroller is the spi-master.We can’t use the camera as SPI Master because we can’t use the microcontroller as SPI Slave, since its pins for that use are already used elsewhere. We are telling the microcontoller via another Pin (P4) whether the camera has some calculation results to deliver.
So, after the SPI-interrupt was executed and data were sent, this P4 is set to 0 and when the main loop has some results, it sets P4 to 1, microcontroller starts communication, P4 gets set to 0, main loop sets it to 1… and so on.
We are having problems with a runtime exception with no error message:
Uncaught exception in ExtInt interrupt handler line 12
Since we might have some problems with our heap (see here: http://forums.openmv.io/viewtopic.php?f=3&t=338) I checked out whether the error occured if we skip the “heap-corrupting”-functions. And it didn’t. But then I added a simple sensor.snapshot() in the main loop and it showed the same error as before.
For debugging I currently have a counter in the main loop, and the error occures not always, and data are successfully sent and printed to serial terminal, but then suddenly it stops with that RuntimeError.
Then I added following instruction before sensor.snapshot() in the main loop:
if not pyb.Pin.board.P4.value(): sensor.snapshot()
So, as long as there can be a spi communication running or being started, there will be no snapshots done.
And the error didn’t appear anymore.
Why does the camera show this behaviour?
Here is the code that is executed in the spi-interrupt:
def _csIntHandler(self, line): try: #self._spi.send_recv(send=self._spiSendData,recv=self._spiRecData, timeout=100) #self._spi.send(self._spitestdata, timeout=1000) self._spi.send_recv(send=self._spiSendData,recv=self._spiRecData, timeout=100) self._intPin.value(0) except OSError as err: print("error os :" + str(err)) pass except NameError as err: print("error name") pass if self._spiRecData == self._startByte and self._spiRecData == self._endByte: self._recValid = 1 self._recBnoAngle = 0 self._recBnoAngle = self._spiRecData & 0xFF self._recBnoAngle |= (self._spiRecData << 8) & 0xFF00 self._recGoalSide = self._spiRecData & 1 self._recReset = (self._spiRecData & (1 << 1)) >> 1 self._recLifted = (self._spiRecData & (1 << 2)) >> 2 self._recOutside = (self._spiRecData & (1 << 3)) >> 3 else: self._recValid = 0