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.
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)
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.
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?
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?
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.
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)
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.
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:
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.
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.