Master-Slave Communication Between Two Jetson Nano over SPI

Have reference to below link.

1 Like

Hii @ShaneCCC ,

Board used in above link is Jetson Xavier NX and I’m using Jetson nano after going through datasheet it seems all pins are same, so I want to ask that will it support for Jetson nano?
Also want to ask that does it work for 2 jetson nano connected via SPI?

Thank You.

Yes, just confirm the PINs connected for loopback test doesn’t matter NX or Nano

1 Like

Hii @ShaneCCC ,
Thank you!! Loopback test runs successfully, now I want to do SPI interface between 2 jetson nano, does loopback code supports for that or should I have to write the code if yes then please guide me with it. Hardware connections will not be tough but help me with software side like what steps should I follow, is there any library which I can use, do we need to add driver for it?

Thank you.

Suppose you can get the spidev_test source code from web.

Hii @ShaneCCC ,
Yes, I have the code will it work for 2 jetson nano, one as master and other is slave and for slave device should I follow this link: How to set to spi slave mode

Thank You.

Hii @ShaneCCC , Help me here.

Thank you.

Yes, follow the relative topic for it.

Thanks

1 Like

Hii @ShaneCCC ,
I set one Jetson nano as master and another as slave, could you please tell me
1.

Jetson nano 1 MISO → Jetson nano 2 MISO
Jetson nano 1 MOSI → Jetson nano 2 MOSI
Jetson nano 1 CLK → Jetson nano 2 CLK
Jetson nano 1 CS → Jetson nano 2 CS

is this hardware connection correct.

  1. should run spidev_test.c on master first and then on slave.
    Is there any changes should I make in spidev_test.c
    https://forums.developer.nvidia.com/t/master-slave-communication-between-two-jetson-nano-over-spi/221229/16?u=prasad.suralkar

Thank You.

Run the slave first. Also make sure your have modify the device tree as slave mode.

1 Like

Hii @ShaneCCC ,
Loopback test run fine on Jetson nano as master device
I have tried loopback test on Jetson nano as slave device

Command :

./spidev_test -D/dev/spidev1.0 -s18000000 -n100 -g30 -p4

Output :

[ 1108.050910] spi-tegra124-slave 7000d600.spi: pm runtime failed, e = -22
can’t set spi mode: Invalid argu[ 1108.057740] audit: type=1701 audit(1600599739.923:6): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=4733 comm="sp6
ment
Aborted

how to verify Jetson nano as slave device.

Thank You.

Hii @ShaneCCC
here I don’t understand what parameters are wrong, program returns 22 i.e. invalid arguments. can you please tell me where is the actual problem. I’m changing speed and other parameters but the result is always same

Thank You.

Did you modify the device tree for SPI slave mode?

Hii @ShaneCCC ,
Thank you for quick reply.
Yes, I have modified the device tree for slave mode.
I think device is set to slave mode so for loopback it didn’t get the clock frequency because on hardware I had short MISO & MOSI. & its only hardware connection i do.

Thank You.

Did you configure those PINs by jetson-io?

Confirm below command.
sudo cat /sys/kernel/debug/tegra_pinctrl_reg | grep -i spi

nvidia@nvidia-desktop:~$ sudo cat /sys/kernel/debug/tegra_pinctrl_reg | grep -i spi
[sudo] password for nvidia:
Bank: 1 Reg: 0x70003050 Val: 0x0000e044 -> spi1_mosi_pc0
Bank: 1 Reg: 0x70003054 Val: 0x0000e044 -> spi1_miso_pc1
Bank: 1 Reg: 0x70003058 Val: 0x0000e044 -> spi1_sck_pc2
Bank: 1 Reg: 0x7000305c Val: 0x0000e048 -> spi1_cs0_pc3
Bank: 1 Reg: 0x70003060 Val: 0x0000e048 -> spi1_cs1_pc4
Bank: 1 Reg: 0x70003064 Val: 0x00006044 -> spi2_mosi_pb4
Bank: 1 Reg: 0x70003068 Val: 0x00006044 -> spi2_miso_pb5
Bank: 1 Reg: 0x7000306c Val: 0x00006044 -> spi2_sck_pb6
Bank: 1 Reg: 0x70003070 Val: 0x00006044 -> spi2_cs0_pb7
Bank: 1 Reg: 0x70003074 Val: 0x00006044 -> spi2_cs1_pdd0
Bank: 1 Reg: 0x70003078 Val: 0x0000e015 -> spi4_mosi_pc7
Bank: 1 Reg: 0x7000307c Val: 0x0000e015 -> spi4_miso_pd0
Bank: 1 Reg: 0x70003080 Val: 0x0000e015 -> spi4_sck_pc5
Bank: 1 Reg: 0x70003084 Val: 0x0000e015 -> spi4_cs0_pc6

Hii @ShaneCCC ,

root@b2qt-jetson-nano-emmc:~#  cat /sys/kernel/debug/tegra_pinctrl_reg | grep -i spi                                                                  
Bank: 1 Reg: 0x70003050 Val: 0x0000e004 -> spi1_mosi_pc0
Bank: 1 Reg: 0x70003054 Val: 0x0000e044 -> spi1_miso_pc1
Bank: 1 Reg: 0x70003058 Val: 0x0000e004 -> spi1_sck_pc2
Bank: 1 Reg: 0x7000305c Val: 0x0000e009 -> spi1_cs0_pc3
Bank: 1 Reg: 0x70003060 Val: 0x0000e015 -> spi1_cs1_pc4
Bank: 1 Reg: 0x70003064 Val: 0x00006004 -> spi2_mosi_pb4
Bank: 1 Reg: 0x70003068 Val: 0x00006044 -> spi2_miso_pb5
Bank: 1 Reg: 0x7000306c Val: 0x00006044 -> spi2_sck_pb6
Bank: 1 Reg: 0x70003070 Val: 0x0000600a -> spi2_cs0_pb7
Bank: 1 Reg: 0x70003074 Val: 0x00006015 -> spi2_cs1_pdd0
Bank: 1 Reg: 0x70003078 Val: 0x0000e015 -> spi4_mosi_pc7
Bank: 1 Reg: 0x7000307c Val: 0x0000e015 -> spi4_miso_pd0
Bank: 1 Reg: 0x70003080 Val: 0x0000e015 -> spi4_sck_pc5
Bank: 1 Reg: 0x70003084 Val: 0x0000e015 -> spi4_cs0_pc6
Bank: 1 Reg: 0x70003088 Val: 0x00002040 -> qspi_sck_pee0
Bank: 1 Reg: 0x7000308c Val: 0x00002000 -> qspi_cs_n_pee1
Bank: 1 Reg: 0x70003090 Val: 0x00002040 -> qspi_io0_pee2
Bank: 1 Reg: 0x70003094 Val: 0x00002040 -> qspi_io1_pee3
Bank: 1 Reg: 0x70003098 Val: 0x00002040 -> qspi_io2_pee4
Bank: 1 Reg: 0x7000309c Val: 0x00002040 -> qspi_io3_pee5
Bank: 0 Reg: 0x70000b70 Val: 0x00000001 -> drive_qspi_comp_control
Bank: 0 Reg: 0x70000b78 Val: 0x00000001 -> drive_qspi_lpbk_control
Bank: 0 Reg: 0x70000a78 Val: 0x00808000 -> drive_qspi_comp

Thank You.

Hii @ShaneCCC, Does loopback successfully run on slave ?

Hii @ShaneCCC ,
spidev_test.c is not working with 2 jetson nano one as master and other as slave, will you elaborate the process to run the test.

SPI_MASTER device log :

root@b2qt-jetson-nano-emmc:~# ./spidev_test -D/dev/spidev1.0 -s18000000 -n100 -g30 -p4                                                                
/dev/spidev1.0: TEST FAILED !!!!! (status:-1)
root@b2qt-jetson-nano-emmc:~#

SPI_SLAVE device log :

root@b2qt-jetson-nano-emmc:~# ./spidev_test -D/dev/spidev1.0 -s18000000 -n100 -g30 -p4                                                                
[  738.768389] tegra-dvfs: rate 408000000 too high for dvfs on sbc2
[  738.774437] spi-tegra124-slave 7000d600.spi: clk_prepare failed: -22
[  738.780885] spi-tegra124-slave 7000d600.spi: pm runtime failed, e = -22
can't set spi mode: Invalid argu[  738.789928] audit: type=1701 audit(1600599370.519:3): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=4696 comm="sp6
ment
Aborted

why one device not wait for another device to run the command .
what to do ?

Thank You.

If the configuration is correct the slave mode will wait master to send data.

Thanks

Hii @ShaneCCC ,
After observing the verbose output, i know that can't set spi mode: Invalid argument this is error. so I’m confused which mode I need to set like master/slave mode or cpol/cphase mode or read only/write only mode.

I think my master works fine bcoz in output i observed that master is sending data but slave is not able to receive it.

root@b2qt-jetson-nano-emmc:~# ./spidev_test -D /dev/spidev1.0 -s1000000 -n10 -g10 -p4 -zzz
using device: /dev/spidev1.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 1000000 Hz (1000 KHz)
no. runs: 10
Using seed:0x5f675722
loop count = 0 
transfer packet size should be from 12 to 131072
loop count = 1 
transfer packet size should be from 12 to 131072
loop count = 2 
transfer packet size should be from 12 to 131072
loop count = 3 
transfer packet size should be from 12 to 131072
loop count = 4 
transfer packet size should be from 12 to 131072
loop count = 5 
transfer packet size should be from 12 to 131072
loop count = 6 
transfer packet size should be from 12 to 131072
loop count = 7 
transfer packet size should be from 12 to 131072
loop count = 8 
transfer packet size should be from 12 to 131072
loop count = 9 
transfer packet size should be from 12 to 131072
/dev/spidev1.0: TEST FAILED !!!!! (status:-1)
====== Transfer stats ====
Transmit:
       total: 0B (0KiB 0MiB)
       total: 0P 
       ioerr: 0B (0KiB 0MiB)
       ioerr: 0P
 Rate:
  wire total: -1B/s (0KB/s)
       total: -1B/s (0KB/s)
  wire total: -1P/s
       total: -1P/s
Receive:
       total: 0B (0KiB 0MiB)
       total: 0P 
        good: 0B (0KiB 0MiB)
        good: 0P
       ioerr: 0P
     dataerr: 0P
 Rate:
        good: -1B/s (0KB/s)
        good: -1P/s
 packet drop: -1/10000

  Total time: 0.000124s

If you have any idea about that mode error help me. I’m also looking into it.
from log can you tell me is my master device working fine.

Thank You.