I am using a Jetson Orin Nano Developer Kit 8GB. When I try to follow the steps in this link: Jetson/L4T/peripheral/ - eLinux.org to implement SPI1 in slave mode and SPI0 in master mode for data transmission and reception, the SPI0 as the master can send data, but the SPI1 as the slave always receives [0, 0, 0, 0, 0, 0, 0, 0]. I used ChatGPT to generate a Python program to achieve data transmission and reception. The Python program is as follows:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import spidev, time, threading
MASTER_BUS = 0
MASTER_DEVICE = 0
SLAVE_BUS = 1
SLAVE_DEVICE = 0
SPI_SPEED = 25000000
SPI_BITS = 8
SPI_MODE = 0
slave_received = None
def spi_slave():
global slave_received
slave = spidev.SpiDev()
slave.open(SLAVE_BUS, SLAVE_DEVICE)
slave.max_speed_hz = SPI_SPEED
slave.bits_per_word = SPI_BITS
slave.mode = SPI_MODE
print("Slave device: Waiting for the first stage of transmission...")
slave_received = slave.readbytes(8)
print("Data received by the slave device:", slave_received)
time.sleep(1)
print("Slave device: Preparing to send data back in the second stage...")
returned = slave.xfer2(slave_received)
print("Data received by the slave device in the second stage:", returned)
slave.close()
def spi_master():
master = spidev.SpiDev()
master.open(MASTER_BUS, MASTER_DEVICE)
master.max_speed_hz = SPI_SPEED
master.bits_per_word = SPI_BITS
master.mode = SPI_MODE
tx_data = [0x55, 0xAA, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44]
print("Master device: Sending data in the first stage:", tx_data)
dummy_rx = master.xfer2(tx_data)
print("Data received by the master device in the first stage (usually meaningless):", dummy_rx)
time.sleep(2)
dummy_tx = [0x00] * 8
print("Master device: Sending dummy data in the second stage:", dummy_tx)
echo_rx = master.xfer2(dummy_tx)
print("Data received by the master device in the second stage:", echo_rx)
master.close()
if __name__ == '__main__':
slave_thread = threading.Thread(target=spi_slave)
master_thread = threading.Thread(target=spi_master)
slave_thread.start()
time.sleep(0.5)
master_thread.start()
slave_thread.join()
master_thread.join()
the result as below:
jetson@yahboom:~$ python spi_test2_20250317.py
Slave device: Waiting for the first stage of transmission...
Data received by the slave device: [0, 0, 0, 0, 0, 0, 0, 0]
Master device: Sending data in the first stage: [85, 170, 255, 0, 17, 34, 51, 68]
Exception in thread Thread-2 (spi_master):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/home/jetson/spi_test2_20250317.py", line 39, in spi_master
dummy_rx = master.xfer2(tx_data)
OSError: [Errno 22] Invalid argument
Slave device: Preparing to send data back in the second stage...
Data received by the slave device in the second stage: [0, 0, 0, 0, 0, 0, 0, 0]
Can you help me solve this problem? Please provide detailed steps. I’m not very familiar with the operation of Jetson Orin Nano. Thank you very much.