ADC using SPI on Xavier

Hi guys,
I connected the ADC (MCP3208) to the Expansion Header (SPI1_MOSI(19), SPI1_MISO(21), SPI1_SCK(23) and SP1_CS0(24)) and tried to read the value of the potentiometer. However, the output result was 0.0V.

With the help of various people, I enabled SPI1 of Xavier.
I maked spidev1.0 occurred at /dev/ directory . However, when running the following program, the value will be 0.0 V.

import spidev
Vref = 3.3
ch0 = [0x06,0x00,0x00]
 
spi = spidev.SpiDev()
spi.open(1,0) #spi1.0
spi.max_speed_hz = 1000000 # 1MHz
time.sleep(0.05)
 
adc = spi.xfer2(ch0)

data = ((adc[1] & 0x0f) << 8) | adc[2]
print(str(Vref*data/4095) + "V")
 
spi.close()

The SPI device voltage level is 3.3V.
I used JetPack4.2.
It has been confirmed using Arduino that the devices are not broken.

What should I do?

Thanks.

If you hook up a logic analyzer or storage scope on the clock and data lines of the SPI device, what do you see on the wires? Does the clock go out? Does the chip select go low? Does data go out/in?

Do you use the spidev_test.c to test the self loop when connect MISO and MOSI?

Thanks.

I used storage scope.
But, there were no data.

Is there anything else to do?

Thank you for your reply.

The results I tried that:

hoge@hoge:~/Documents/c++/spi$ sudo ./spidev_test 
[sudo] password for hoge:
open device : /dev/spidev1.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 00  | ................................

This doesn’t seem to work.
I changed to /dev/spidev1.0.

spidev_test.c

L.35 static const char *device = "/dev/spidev1.0";

Is there anything else to change?

Have you changed the pinmux for extension header?

No.
I don’t know how to change it.
What file should I change and how to change it ?

Have a check below topic.

[url]https://devtalk.nvidia.com/default/topic/1049170/jetson-agx-xavier/spi1-not-work-on-xavier/post/5325856/#5325856[/url]

You can try Shane’s method, unfortunately, I try it but it does not work. You can try to change the pinmux first, then we can talk it again.

Thanks a lot !

I have two more questions.
1)
“tegra19x-mb1-pinmux-p2888-0000-a04-p2822-0000-b01.cfg” is in 3 places, bootloader, bootloader/t186ref/BCT and sources/hardware/nvidia/platform/t19x/galen/bct/pinmux .
So which file should I change ?

After changing the file, can I flush the kernel with the following command ?

sudo ./flash.sh -k kernel-dtb jetson-xavier mmcblk0p1

I think you should use pinmux xml and a python script to create the .cfg file, and then replace the original file at bootloader/t186xx, unfortunately, I use this method to change pinmux but it does not work, I don’t know why, you can try again, hope you can make it work.
the command should be used as you type out.

Thanks Gaosiy!

I’ll try them.

If you have some progress, can you show it out?

Should I do the following?

  1. Download the pinmux spreadsheet from the Jetson Download Center
    Jetson Download Center | NVIDIA Developer
  2. Change the contents of the sheet
  3. Click the “Generate DT File” button to create dtsi files
  4. Execute the dts2cfg to generate cfg file

If so, where should I change??

you need find the pull botton to change the different function of a pin, then click the Generate DT file

Thanks to everyone, I was able to make spi enable.

I did the following.

  1. Flash the Xavier using SDK manager
    This is because Xavier boot failed.

  2. Edit the following line of the JetPack_4.2_Linux_P2888/Linux_for_Tegra/bootloader/t186ref/BCT/tegra19x-mb1-pinmux-p2888-0000-a04-p2822-0000-b01.cfg

pinmux.0x0243d040 = 0x00000400; # spi1_sck_pz3: rsvd1, pull-down, tristate-enable, input-enable, lpdr-disable
pinmux.0x0243d020 = 0x00000450; # spi1_miso_pz4: rsvd1, pull-down, tristate-enable, input-enable, lpdr-disable
pinmux.0x0243d058 = 0x00000400; # spi1_mosi_pz5: rsvd1, pull-down, tristate-enable, input-enable, lpdr-disable
pinmux.0x0243d010 = 0x00000400; # spi1_cs0_pz6: rsvd1, pull-up, tristate-enable, input-enable, lpdr-disable
pinmux.0x0243d050 = 0x00000400; # spi1_cs1_pz7: rsvd1, pull-up, tristate-enable, input-enable, lpdr-disable
  1. $ cd JetPack_4.2_Linux_P2888/Linux_for_Tegra/kernel/dtb/
  2. $ dtc -I dtb -O dts -o /tmp/tegra194-p2888-0001-p2822-0000_test.dts tegra194-p2888-0001-p2822-0000.dtb
  3. $ gedit /tmp/tegra194-p2888-0001-p2822-0000_test.dts
spi@3210000 {
                            compatible = "nvidia,tegra186-spi";
                            reg = <0x0 0x3210000 0x0 0x10000>;
                            interrupts = <0x0 0x24 0x4>;
                            #address-cells = <0x1>;
                            #size-cells = <0x0>;
                            iommus = <0x2 0x20>;
                            dma-coherent;
                            dmas = <0x1e 0xf 0x1e 0xf>;
                            dma-names = "rx", "tx";
                            spi-max-frequency = <0x3dfd240>;
                            nvidia,clk-parents = "pll_p", "clk_m";
                            clocks = <0x4 0x87 0x4 0x66 0x4 0xe>;
                            clock-names = "spi", "pll_p", "clk_m";
                            resets = <0x5 0x5b>;
                            reset-names = "spi";
                            <u>status = "okay";</u>
                            linux,phandle = <0x172>;
                            phandle = <0x172>;
[u]                            spidev@0 {
                                          compatible = "spidev";
                                          reg = <0x0>;
                                          spi-max-frequency = <0x1312d00>;
                            };[/u]
              };
  1. $ dtc -I dts -O dtb -o tegra194-p2888-0001-p2822-0000.dtb /tmp/tegra194-p2888-0001-p2822-0000_test.dts
  2. $ sudo ./flash.sh -r jetson-xavier mmcblk0p1

It worked well. Thank you!!

Cancel post.

that’s great!
do you test the spidev_test.c?

Yes !

Hi bunmp5236!
I do what you say.But,it doesn’t work for me…
I still can’t find /dev/spidev* in my xavier.