I have two Jetson Nano devices that need to exchange data over SPI protocol. It is my first and only project with Jetson Nano, so I am completely new to the SPI or anything regarding low-level coding.
In the project, I want to use Daisy Chain to communicate, for starters I have used only two devices to test the data communication between them.
Using the following link on page 4, I made one a slave. https://www.nxp.com/files-static/training_pdf/26821_68HC08_SPI_WBT.pdf What it says is that in order to select one device as a slave you need to connect SS to ground to make it low. So I have connected pin 24 (SPI_1_CS0) to pin 20 which is ground. For the master, I have put pin 24 (SPI_1_CS0) to pin 2 (5.0 VDC). I intended to set it high for it to become the master.
I have used /opt/nvidia/jetson-io/jetson-io.py
to configure the pins. After running sudo modprobe spidev
the pins were configured.
Output of ls /dev/spi*
is
/dev/spidev0.0 /dev/spidev0.1 /dev/spidev1.0 /dev/spidev1.1
After running the following code on the slave I received useless data. Since slave mode should have been activated, I should not be able to read data unless Master is sending some.
import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = 250000
def read_spi(channel):
spidata = spi.xfer2([0,(8+channel)<<4,0])
return ((spidata[1] & 3) << 8) + spidata[2]
def readData():
spidata = spi.readbytes(8)
return spidata
try:
while True:
#channelData = read_spi(0)
channelData = readData()
print (channelData)
time.sleep(.1)
except KeyboardInterrupt:
spi.close()
channelData
can be received with the other function. But it does not make the result any different.
[20, 206, 54, 93, 19, 151, 211, 199]
[84, 10, 89, 184, 126, 82, 49, 78]
[189, 32, 110, 143, 231, 226, 76, 116]
[102, 56, 174, 123, 186, 145, 148, 161]
[105, 254, 152, 155, 88, 147, 191, 174]
[38, 221, 219, 179, 161, 102, 107, 31]
[101, 141, 98, 80, 20, 254, 25, 50]
[88, 0, 0, 44, 197, 73, 32, 49]
[107, 60, 44, 230, 91, 56, 172, 4]
[21, 156, 120, 165, 99, 137, 245, 204]
[15, 34, 164, 215, 255, 187, 34, 86]
[18, 215, 67, 227, 234, 1, 237, 142]
[71, 124, 36, 238, 86, 240, 105, 189]
[29, 27, 63, 232, 239, 40, 189, 61]
[5, 217, 209, 14, 96, 24, 181, 97]
[158, 121, 125, 93, 224, 125, 97, 129]
[75, 92, 95, 183, 47, 14, 111, 164]
Do I need more configuration to be done if I want to make one a slave or am I doing something wrong with the coding?
Any links or code example is appreciated.