communication between two OpenMVs via SPI

General discussion about topics related to OpenMV.
roc
Posts: 2
Joined: Tue Dec 11, 2018 8:06 am

communication between two OpenMVs via SPI

Postby roc » Tue Dec 11, 2018 9:09 am

Hi,
I have three OpenMVs. I want to make one OpenMV act as a controller and another two OpenMVs will receive the signal from the controller for capturing scenes synchronously. Then the controller can also receive two scenes from that two OpenMVs and make sure the two scenes are captured at the same time. I first try to use SPI protocol to test between two OpenMVs making one act as a master and another a slave (Pin connection: Master.P0-->Slave.P1, Master.P1-->Slave.P0, Master.P2-->Slave.P2, Master.P3-->Slave.P3, Master.GND-->Slave.GND). The codes in the Master and the slave are very simple:
#Master
from pyb import Pin, SPI

cs = Pin("P3", Pin.OUT_PP)
cs.high()
buf = ‘a'
# The hardware SPI bus for your OpenMV Cam is always SPI bus 2.
spi = SPI(2, SPI.MASTER, baudrate=115200, polarity=0, phase=0)
while(True):
cs.low()
spi.send_recv(buf,buf,timeout=500)
print(buf)
cs.high()
#-------------
#Slave
from pyb import SPI, Pin

cs = Pin("P3", Pin.IN)
cs.high()
buf = ‘b'
spi = SPI(2, SPI.SLAVE, baudrate=115200, polarity=0, phase=0)
while(True):
cs.low()
spi.send_recv(buf,buf,timeout=500)
print(buf)
cs.high()
However, those codes do not work (of course the Pin connection maybe is wrong, because i am a novice). Therefore, who can help me for my purpose, thanks very much.
User avatar
kwagyeman
Posts: 3209
Joined: Sun May 24, 2015 2:10 pm

Re: communication between two OpenMVs via SPI

Postby kwagyeman » Tue Dec 11, 2018 1:00 pm

Please use the UART to send data. The SPI bus can't really be used for slave device communication. The UART is much better for sending data between two devices. If you need to see a UART example checkout the Pixy Emulation script.
Nyamekye,
roc
Posts: 2
Joined: Tue Dec 11, 2018 8:06 am

Re: communication between two OpenMVs via SPI

Postby roc » Wed Dec 12, 2018 6:21 am

kwagyeman wrote:
Tue Dec 11, 2018 1:00 pm
Please use the UART to send data. The SPI bus can't really be used for slave device communication. The UART is much better for sending data between two devices. If you need to see a UART example checkout the Pixy Emulation script.
thanks very much for your reply. I will try to study that example. Wish that it can fulfill my requirement.

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 4 guests