Receiving garbage values, Nano SPI communication via Python spidev package

Hello,

I am trying to get the Jetson Nano (2GB) to communicate with the MSP430FR6989 chip using SPI with help from the Python spidev package. I’ve got the Nano configured for SPI1 with the help of jetson-io and I am able to send and receive.

However, the Nano receives garbage values from the MSP430 and the MSP430 also receives garbage values from the Nano. Does anyone have experience with the spidev Python package and could offer any insight as to what could be the issue?

The function in question:

def easy_spi_test():
    failed = False

    # SPI settings
    bus = 0
    device = 1
    speed = 8000000

    # Enables SPI Communication
    spi = spidev.SpiDev()

    # SPI Setup
    try:
        print("Attempting to open SPI port {0}, device {1}...".format(bus, device))
        spi.open(bus, device)
        print("Connection established")
        print("Applying settings...")
        spi.max_speed_hz = speed
        spi.lsbfirst = False
        spi.mode = 0b10
        print("Settings applied successfully!")
    except Exception as e:
        print("Failed to apply settings")
        print(e)
        failed = True

    if not failed:
        print("Attempting transmission...")

        while True:
            # spi.writebytes2([0x62, 0x79, 0x74, 0x65])
            spi.xfer2([0x62, 0x79, 0x74, 0x65])
            print(spi.readbytes(10))

        print("Transmission complete")

    
    if spi:
        spi.close()

Output of MSP430 to Nano:
msp-to-nano-output.txt (5.6 KB)

This output shows when the transmission occurs from the MSP to the Jetson.

Output of Nano to MSP430 is just a bunch of garbage characters.


On the Nano I’ve got the SPI connections at pin’s:

19 - SPI_1_MOSI
21 - SPI_1_MISO
23 - SPI_1_SCK
24 - SPI_1_CS1

I am using the spidev function: xfer2
spi.xfer2([0x62, 0x79, 0x74, 0x65)]


From my understanding, the spidev package sends and reads an array of bytes. However, I’m not sure why the Nano would read a 3 digit byte such as 255, 149, etc.

Any help would be appreciated.

Edit: This is on Jetpack 4.6, L4T 32.6.1

Could you verify by spidev_test?

I have not yet been able to verify it by using spidev_test. I tried to run this: linux/spidev_test.c at master · torvalds/linux · GitHub

but ran into a series of errors regarding SPI_TX_OCTAL SPI_RX_OCTAL. Perhaps I am running the incorrect spidev_test?

You can download the binary file from below link.
Rename it as spidev_test and chmod +x for it.

1 Like

I ran the spdev_test with the following settings:

./spidev_test -D /dev/spidev0.1 -s 8000000 -g 16 -n 25 -p 1 -z

I got the following result:

using device: /dev/spidev0.1
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 8000000 Hz (8000 KHz)
no. runs: 25
/dev/spidev0.1: TEST FAILED !!!!! (status:-1)

I tried to mimic my argument to my settings in the code, however it gives me the Invalid argument return code. Am I providing the incorrect arguments?

 

Update: I used spidev_test to perform a loopback (connected pins 19 and 21 together) test like so:

sudo ./spidev_test -D /dev/spidev0.1 -g 12

Received the message:
/dev/spidev0.1: TEST PASSED

However, with this setup, my Python function still fails to read any bytes transmitted.

1 Like

For the loopback test result tell the pin configure without problem.
Maybe try spidev_test to check if able read/write from MSP430

The pin configuration was setup using Jetson-IO, same as before. ALl I did was unplug all the wires and shorted pins 19 and 21.

 

I tried the spidev_test with the MSP430, but it gave me TEST FAILED, status code -1. I was able to verify spi communication between two MSP430 devices, however unable to get it working with the Nano.

 

What is the spidev_test doing?

You may need confirm the transfer mode and speed configure for both Jetson and MSP430.

We confirmed the transfer mode and speed for both the Nano and MSP430 to be the same. However, still no success with communicating between the two platforms via SPI. I believe the issue may be related to the Python spidev package as the spidev_test confirmed SPI communication to be working on the Nano and my team was able to confirm SPI communication on the MSP430. Due to time constraints, we opted to go with using UART and was able to get that working with only a few issues.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.