NVIDIA Orin Nano SPI loopback test not receiving data

So right now I am trying to ensure that the SPI hardware setup is working properly, because the main goal of this project is to collect ADC values sent via SPI from a PIC16F1517 from a signal acquisition circuit for voice, however, I just wanted to ensure that actual data was being read on the Orin Nano’s side. I will attach a code I am using to test the SPI hardware is correctly sending and receiving data.

import spidev
import time

Initialize SPI

spi = spidev.SpiDev()
spi.open(0, 0) # Open SPI bus 0 (spi1 from pin config), CS0
spi.max_speed_hz = 62500 # Set the speed
spi.mode = 0b00 # SPI mode 0

Function to test SPI loopback

def spi_loopback_test():
test_data = [0xAA, 0x55, 0xFF] # Example data to send
print(f"Sending data: {test_data}")

# Send data and read the response (loopback from MOSI to MISO)
response = spi.xfer2(test_data)
print(f"Received data: {response}")

# Check if sent and received data match
if test_data == response:
    print("Loopback Test Passed!")
else:
    print("Loopback Test Failed!")

Main loop to continuously test loopback

try:
while True:
spi_loopback_test()
time.sleep(1) # 1 second delay between tests
except KeyboardInterrupt:
print(“Loopback Test Interrupted.”)
spi.close()

I used command line sudo /opt/nvidia/jetson-io/jetson-io.py to manually configure pin functionality to be spi1 (not sure if this means SPI bus because the actual pinout given by NVIDIA documentation shows that pins 19,21,23,24,26 have SPI0 in front of them for the MOSI,MISO,SCK and CS pins). When running the program, the loopback function is working as in it is evaluating the if statement correctly, giving me hope that the SPI is working, however, the values do not print as ‘Received data’. Instead I just see 0’s. Im not really sure what is happening or how to fix it.

Hi leotemper121,

Are you using the devkit or custom board for Orin Nano?
What’s the Jetpack version in use?

Could you share the block diagram of your connection to verify SPI loopback test?

Hi Kevin,

I am using the devkit for the Orin Nano and I flashed it with the Jetpack 6.1 image provided NVIDIA’s guide to boot the Orin Nano via the JetPack SDK page.

Im not sure if the image uploaded or not of my block diagram, however, it is a very crude block diagram but I will try and explain it in words to better assist the visualization. I essentially just have a female to female wire connected from pin 19 (SPI0_MOSI) to pin 21 (SPI0_MISO). I left pin 24 (SPI0_CS0) and pin 23 (SPI0_SCK) unconnected as I’m under the impression that for a loopback test leaving these unconnected is okay but could you clarify that this is correct?

Again to reiterate what I’m getting on the terminal is the following:

Sending data: [170, 85, 255]
Received data: [0, 0, 0]
Loopback Test Passed!

Where I’m expecting this output from the terminal:
Sending data: [170, 85, 255]
Received data: [170, 85, 255]
Loopback Test Passed!

The test passes, however, the received data is not being printed out in the terminal how I want it to, the reason I want this to happen is because I want to be able to visualize the data coming from my other MCU (slave to the Orin Nano) to ensure proper communication in respect to the ADC values being sent from my other MCU. NOTE :(However, just to clarify this is not the problem I want to discuss at the moment, this problem I posted is in regards to the loopback test, I just want to give a full visualization of why I need this to work as expected)

Correct, they should be fine to verify SPI loopback test.

Please refer to the following steps on the Orin Nano devkit to verify SPI loopback test.

1. Run Jetson-IO to configure the SPI pins
$ sudo /opt/nvidia/jetson-io/jetson-io.py
Configure Jetson 40pin Header => Configure header pins manually => Select "spi1 (19,21,23,24,26)" => Back -> Save pin changes => Save and reboot to reconfigure pins

2. Probe SPI driver
$ sudo modprobe spidev

3. Build spidev_test tool
$ wget https://raw.githubusercontent.com/torvalds/linux/v4.9/tools/spi/spidev_test.c
$ gcc -o spidev_test spidev_test.c

4. Run the tool to verify
$ sudo ./spidev_test -D /dev/spidev0.0 -O -H -v -p "HelloWorld123456789abcdef"

So this is the response in the terminal after following your commands, it does work at least on the transmission, not sure if it is supposed to be receiving the data as well and printing the same? if that is the functionality we are expecting from this test then I think it is not working.

Just as an update, I accessed the device tree to see what the pin configuration was like for SPI, I attached it to this reply. However, I am not really sure what I am looking at as I am completely new to developing with this platform. I did not manually change anything, but from what I can gather, I believe SPI1 bus is configured by spi@3250000 but I am not completely sure

No, it should be spi@3210000 for the SPI from 40 pins expansion header (PIN19 & PIN21).
Do you modify anything in device tree? Or it is pure JP6.1 on the Orin Nano devkit?

It seems you can’t receive the data you sent.
I’ve verified it working on my devkit as following.

nvidia@ubuntu:~$ sudo ./spidev_test -D /dev/spidev0.0 -O -H -v -p "HelloWorld123456789abcdef"
spi mode: 0x3
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  | HelloWorld123456789abcdef
RX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  | HelloWorld123456789abcdef

Please share the full dmesg and device tree for further check.

No I have not modified anything in the device tree, I will add that I have downloaded AI models and been developing some scripts in python (NeMo ASR and a transformer Model MarianMT) to do a simple transcription and text to text translation from EN to ES. However, I am not entirely sure if this was the source of the problem, I do highly doubt this is the issue though. I do have a virtual environment active, not sure if this could affect the SPI bus?

Also yes, on my Orin Nano Dev Kit, it is pure JP6.1 and I have not touched anything to do with the system other than add some directories to the bash file.

I am not entirely sure if this is what you meant for the dmesg, as when I try to run the command

dmesg | grep -i dtb

The terminal does not return anything and fails to execute the command. This is what I could gather at least. if this is not what you were looking for, could you provide me with steps to get to the results you want to further check the issue?


I also tried extracting the dtb file and when I did I got the following return in the terminal.
extractingdtb.txt (32.3 KB)
Not sure if the response from the terminal indicates something terribly wrong with the setup.

I also tried searching in the actual extracted.dts file for anything related to SPI and received this in the terminal, not sure if this is useful?

Just as an update, here is how I have the header tool configured.

Here it shows that the corresponding pins for SPI1 bus are correctly enabled. However, I am still having trouble receiving the correct data that was sent via the loopback test. Would the simplest solution be to flash a new image (JP6.1) onto the nano and restart with my project?

sudo cat /sys/kernel/debug/tegra_pinctrl_reg | grep -i spi

I tried running that command in my terminal, however, I get the following output in the terminal.

(aienv) rcl@rcl-desktop:~/AI Translator$ sudo cat /sys/kernel/debug/tegra_pinctrl_reg | grep -I spi
cat: /sys/kernel/debug/tegra_pinctrl_reg: No such file or directory

Could you clarify why im getting this error?

EDIT:

I figured that the directories had changed so I went looking for new directories of where this might be located and I arrived at this:

temp.txt (316.6 KB)
So I ran the following command to decompile the active DTB file to a DTS file that I have attached above. I have not modified anything in the file.

sudo dtc -I dtb -O dts -o temp.dts /boot/dtb/kernel_tegra234-p3768-0000+p3767-0005-nv.dtb

Im not sure if this is specifically what you are looking for when you mentioned the device tree?

EDIT:

I was able to obtain the dmesg as you had requested earlier in the conversation, I have attached it in the following text file.
dmesg_output.txt (64.2 KB)

@KevinFFF Please let me know if there is any update or steps you could have me try to resolve this SPI issue, thanks.

Have you used Jetson-IO to configure the pinmux for SPI pins?

No, they are 2 info.
Please share full dmesg mean the result of sudo dmesg on your board.
For the device tree, you can run the following command and share extracted_proc.dts.

$ sudo dtc -I fs -O dts -o extracted_proc.dts /proc/device-tree

That node is only valid in r32.

Okay, your device tree looks good to me.

[   11.077254] spi-tegra114 3210000.spi: Adding to iommu group 1
[   11.104434] spi-tegra114 3230000.spi: Adding to iommu group 1

Okay, I’ve checked the log you shared.

Could you run sudo modprobe spidev to load the driver before running spidev_test?

Yes I have used the Jetson-IO to set the SPI1 bus on the 40 pin header, I rebooted my Orin Nano to ensure it was active.

In this next image, I have ran sudo mod probe spidev, however it does not seem to mitigate the issue.

Could the issue be the way the received data isn’t in the correct data type and might cause an issue with displaying it in the terminal?

Have you confirmed that you’ve short PIN19 and PIN21?

This workflow has been verified from us on the Orin Nano devkit with JP6.1(R36.4.0).

Could you get a scope to measure the signal?

And also share the result of the following commands to check pinmux value:

$ sudo busybox devmem 0x0243d040 //SPI1_MOSI
$ sudo busybox devmem 0x0243d018 //SPI1_MISO
$ sudo busybox devmem 0x0243d028 //SPI1_SCK
$ sudo busybox devmem 0x0243d008 //SPI1_CS0

Yes, I had probed pins 23 and 24 (SCK and CS0) and saw no activity when running the spidev_test.c steps. However, when I did run this script:

import spidev
import time

# Intialize SPI
spi = spidev.SpiDev()
spi.open (0,0) # Open SPI1, CS0
spi.max_speed_hz = 62500 # Set matching clock speed
spi.mode = 0b00 # Set matching SPI Modes (SPI mode 0)

# Function to read two bytes of audio data
def read_audio_data():
    response = spi.xfer2([0x00,0x00]) # Send dummy bytes to read from the PIC
    combined_value = (response[0] << 8) | response[1]
    audio_data = combined_value # Combine MSB and LSB to form the 10-bit audio data
    return audio_data

# Main loop to continously read data
try:
    while True:
        audio_value = read_audio_data()
        print(f"Received Audio Data (10-bit): {audio_value}")
        time.sleep(0.0000625) # Maintain 16k kHz sampling rate
except KeyboardInterrupt:
    print(f" Process Manually Interrupted.") # CTRL + C
    spi.close()

I probed the pins 23 and 24, and did see some activity reflecting how I coded it. Granted, this was about a week or two ago and have not tested in the same way since, however, I could test again tomorrow to see if I can replicate the behavior. If there are other tests I could conduct using an oscilloscope you suggest or recommend, please let me know and I will follow those tests, if any.

So initially, I tried your steps again, the proven steps you had mentioned assuming that I some how built the script wrong, I deleted the previous files for spidev_test.c and ran the commands again as shown in the following image:

As you can see, I am still running into the same issue where it does not seem to be receiving the data.

As for the commands to check the pinmux value, I did not have busybox installed, so I had installed it and then ran the commands, as shown by the following image:

These were the results, are these the results we are expecting?

Please check the data from oscilloscope if the same as what you sent and whether the level is expected or not.

I’m curious about why you don’t have busybox. It should be available to be used by default.
Have you confirmed that you are using Orin Nano devkit and used SDK Manager to setup the board?

They seem expected result to me.
Let me share mine as following:

So I tested the following by probing pin 19 and 23 (SPI1 BUS MOSI and SCK) by following spidev_test.c script version, However, instead of the “helloworld”, I wrote “bye” for simplicity. Here is the command I ran.

When probing the pins, I did see activity from both the MOSI and SCK pins as shown by the following oscilloscope screen shot.

From what I can gather, the data is being sent correctly and yes, I did try and shorting pins 19 and 21 again to ensure that the test still doesn’t work. After I attempted to run the test with pins 19 and 23 shorted, I still do not receive data from the test as shown by the following image.

Yes, I am using the Orin Nano Dev Kit and I did not use the SDK manager to setup the board, I used the following links. Jetson Orin Nano Developer Kit Getting Started | NVIDIA Developer and JetPack SDK | NVIDIA Developer. I followed the first link for the steps and I used a 256GB SD card. I initially flashed the board with JP 5.1.3 to update the firmware and then flashed the board with JP 6.1 using the SD card and balenaEtcher. I was under the impression (from the first link) that all I needed to do was flash it via the SD card, I was aware of the SDK manager method, however, since I am new to this kind of developing, I decided to go via the SD card method. Do I need to use the SDK manager to setup the board?

EDIT:

I know I had linked the initial setup for the Orin Nano, however, I used these steps linked here: 🚅 Initial Setup Guide - Jetson Orin Nano - NVIDIA Jetson AI Lab. However, after these steps I did not do anything else for the setup and booted up the Orin Nano and this is how I setup the Orin Nano.

Hi, I have the same problem, I’m using a jetson Nano. I’m new to using the card, what is “sudo busybox” for?