Jetson TX2 spidev

Hi,

I’m new in Jetson and I work on spi communication between Jetson and MPU9255. I tested spidev with loopbacking and it’s fine. There are SPI1, SPI2 and SPI3 but only SPI1 works when I compile and run the code. As you see below, I tried spidev 3.1 (also spidev 3.0, spidev2.1 and spidev 2.0) but there is no data on SPI2 and SPI3 lines (Code 2). I’m new to use that system and try something every new day but now I’m stuck.

Thanks in advance

Code 1:

static const char *device = “/dev/spidev3.1”;
static uint32_t mode = 3;
static uint8_t bits = 8;
static uint32_t speed = 500000;
static uint16_t delay;
static int verbose;

Code 2:

sudo ./spitest -D /dev/spidev1.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
RX | 01 02 03 04 05 06 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D | …@…▒…▒.

sudo ./spitest -D /dev/spidev2.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | …

sudo ./spitest -D /dev/spidev3.1
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | …

Hi burakberzener!

Welcome to the wonderful world of Tegra SPI numbering where the numbers are made up and the rules… are actually pretty strict.

First, the TX2 spi addresses look like this:

/*
 * SPI Bus Addresses
 *
 * spi0 = spi@3210000 - J23 Display Expansion Connector, SPI2.0
 * spi0 = spi@3210000 - J22 Camera Expansion Connector, SPI2.1
 * spi1 = spi@c260000 - J23 Display Expansion Connector, SPI0
 * spi3 = spi@3240000 - J21 Expansion Header, SPI1
 */

I have not figured out any correlation between the lowercase spi# designations from the device tree and the uppercase SPI# designations in the Developer Kit Carrier Board Specifications. There’s either some super significant historical reason… or the engineers just started randomly numbering things.

So for your examples above I would expect:

  1. spidev3.1 to come out of J21 SPI1.1 (that's header pin 26)
  2. spidev1.0 to come out of J23 Display Expansion Connector SPI0.1
  3. spidev2.0 to not come out anywhere, I don't think it is routed on the devboard

Thanks for you reply Atrer!

I see you’re good at this board. But unfortunetly I don’t use Jetson DevKit, my one is special designed carrier board. Anyway, your news are very helpful for me in this way. Also I want to learn more things about Jetson, GPIO, SPI and UART… Could you advice me useful links or source in that case? I want to use spidev library but I didn’t find enoughly source even in spidev site. And if t’s possible I want to use C programming language.

There is an official gpio library, but its python:

SPI is one of those things that is usually handled by a kernel driver and device tree entry. Spidev is only really used for simple debugging. You can look at my MCP2515 guide on how to setup a device for SPI in the device tree.

UART is pretty straightforward, if you search the forums you should find quite a few examples of getting the UART ports set up.

Also if you can’t find information for the TX2 you can usually find something for the RPi that can help.

Looks like someone else is trying to do the same thing:
https://devtalk.nvidia.com/default/topic/1037096/closed-mpu9255-on-spi0-/

How can I reach my spi gpio pin numbers and configure them in spidev ?

Have a look at the “Modifying the Pinmux Configuration” section here:
https://elinux.org/Jetson/TX2_SPI

Hi Atrer

This tutorial is for enabling SPI in the kernel for Jetson TX2 with L4T R28.1 (JetPack 3.1) through R32.1 (JetPack 4.2)

However, when I run ./getKernelSources.sh, I got an error:

==== L4T Kernel Version Mismatch! =============

the L4T kernel source version is 28.2.1, however the L4T
version in JetPack4.2 is 32.1. How can I fix the problem?

Ridgerun has the best guide on compiling the kernel, make sure you get the 32.1 sources.

I would follow that in place of the “Downloading the Kernel Sources” section of that elinux guide.