This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM3358: SPI read issue

Other Parts Discussed in Thread: ADS1256

I am currently working with BBB to get data from adis16365 through spi but not able to make it work.adis16365 is of adis16400 family.
I have added the following configuration in am335x-boneblack.dts file.

	spi0_pins_default: spi0_pins_default {
		pinctrl-single,pins = <
			AM33XX_IOPAD(0x950, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_22 (A17) spi0_sclk SCLK */
			AM33XX_IOPAD(0x958, PIN_INPUT_PULLUP  | MUX_MODE0)  /* P9_18 (B16) spi0_d1   MISO */
			AM33XX_IOPAD(0x954, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_21 (B17) spi0_d0   MOSI */
			AM33XX_IOPAD(0x95c, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_17 (A16) spi0_cs0  CS0  */	
			AM33XX_IOPAD(0x960, PIN_OUTPUT_PULLUP | MUX_MODE0) /* P9_16 (C15) spi0_cs1  CS1  */
		>;
}; &spi0 { pinctrl-names = "default"; pinctrl-0 = <&spi0_pins_default>; status = "okay"; ti,spi-num-cs = <2>; ti,pindir-d0-out-d1-in = <1>; spidev@1 { compatible = "adi,adis16400"; spi-max-frequency = <1000000>; reg = <1>; //chipselect 1 spi-cpol = <1>; spi-cpha = <1>; };};

I have also loaded the driver of adis16400 through the developer shell. The iio:device1 is visible in /sys/bus/iio/devices. Doing a 'ls' in this directory will list the following values.

root@beaglebone-yocto:/sys/bus/iio/devices/iio:device1# ls
buffer					  in_magn_scale
current_timestamp_clock			  in_magn_x_raw
dev					  in_magn_y_raw
in_accel_filter_low_pass_3db_frequency	  in_magn_z_raw
in_accel_scale				  in_temp0_offset
in_accel_x_calibbias			  in_temp0_raw
in_accel_x_raw				  in_temp0_scale
in_accel_y_calibbias			  in_voltage0_supply_raw
in_accel_y_raw				  in_voltage0_supply_scale
in_accel_z_calibbias			  in_voltage1_raw
in_accel_z_raw				  in_voltage1_scale
in_anglvel_filter_low_pass_3db_frequency  name
in_anglvel_scale			  of_node
in_anglvel_x_calibbias			  power
in_anglvel_x_raw			  sampling_frequency
in_anglvel_y_calibbias			  scan_elements
in_anglvel_y_raw			  subsystem
in_anglvel_z_calibbias			  trigger
in_anglvel_z_raw			  uevent
in_magn_filter_low_pass_3db_frequency

But almost all of these values return 0. For instance, 

root@beaglebone-yocto:/sys/bus/iio/devices/iio:device1# cat in_accel_x_raw 
0
root@beaglebone-yocto:/sys/bus/iio/devices/iio:device1# cat in_anglvel_x_raw 
0

I am also getting this error when I grep iio through dmesg: 

root@beaglebone-yocto:~# dmesg | grep iio
[   11.084613] iio iio:device1: Device ID(16400) and product ID(0) do not match.
[   11.165153] iio iio:device1: adis16400: prod_id 0x0000 at CS1 (irq 0)

How can this be solved? Any help is highly appreciated.

  • Amod Amatya said:
    AM33XX_IOPAD(0x950, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_22 (A17) spi0_sclk SCLK */

    Change the above pinmux setting to:

    AM33XX_IOPAD(0x950, PIN_INPUT_PULLUP | MUX_MODE0)  /* P9_22 (A17) spi0_sclk SCLK */

    For details see Note (1) below Table 24-4 in the AM335x TRM Rev. P.

  • Hy Biser,

    Thank you so much for your response. It worked perfectly.

    Kind Regards,
    Amod

  • Hy Biser,

    I have one more problem. With the CS0 pin, I have connected an ADC ADS1256. For now I am just trying to read the chip ID. Since the driver for this device is not provided by the kernel itself, I have just added the spidev node as:

    	spidev@0 {
    		compatible = "spidev";
    		spi-max-frequency = <1000000>;
    		reg = <0>;    //chipselect 0
    		spi-cpol = <0>;
    		spi-cpha = <1>;
    	};

    Remaining configuration are all same. I am writing to just read the chip ID with the command:

     $ spidev_test --verbose --device /dev/spidev0.0 --cpha --speed 1000000 -p '\x10\x00' 

    Everytime, I get a random value. Any idea, where I could have possibly gone wrong?

    Whenever I grep spi with dmesg, I get the following warnings and errors:

    root@beaglebone-yocto:~# dmesg | grep spi
    [    2.596437] spidev spi0.0: buggy DT: spidev listed directly in DT
    [    2.605167] WARNING: CPU: 0 PID: 1 at drivers/spi/spidev.c:730 spidev_probe+0x74/0x1ac
    [    2.653085] [<c013780c>] (warn_slowpath_null) from [<c06ed104>] (spidev_probe+0x74/0x1ac)
    [    2.660314] [<c06ed104>] (spidev_probe) from [<c06e941c>] (spi_drv_probe+0x90/0xac)
    [    2.667022] [<c06e941c>] (spi_drv_probe) from [<c067345c>] (driver_probe_device+0x240/0x308)
    [    2.720185] [<c06706c4>] (device_add) from [<c06ea114>] (spi_add_device+0xf4/0x134)
    [    2.726882] [<c06ea114>] (spi_add_device) from [<c06ea714>] (of_register_spi_device+0x2c8/0x338)
    [    2.734769] [<c06ea714>] (of_register_spi_device) from [<c06eadd4>] (spi_register_controller+0x3d4/0x5e8)
    [    2.743478] [<c06eadd4>] (spi_register_controller) from [<c06eb02c>] (devm_spi_register_controller+0x44/0x78)
    [    2.752551] [<c06eb02c>] (devm_spi_register_controller) from [<c06eeab0>] (omap2_mcspi_probe+0x314/0x384)
    [    2.761245] [<c06eeab0>] (omap2_mcspi_probe) from [<c067546c>] (platform_drv_probe+0x58/0xa4)
    [    2.821011] [<c06753b4>] (__platform_driver_register) from [<c0f40308>] (omap2_mcspi_driver_init+0x20/0x28)
    [    2.829907] [<c0f40308>] (omap2_mcspi_driver_init) from [<c010364c>] (do_one_initcall+0xc8/0x200)
    


    I have looked into the data sheet of ADS1256 multiple times to confirm the spi mode, commands and register values, tried with different frequencies as well, but no good response.
    Your help is highly appreciated.

    Regards,
    Amod

  • Amod,

    Do you use AM3335x TI PSDK Linux? If yes, which version?

    Please provide me your full dts file (you can attach it) or at least all the spi info.

    Check also below e2e thread, which discuss similar issue.

    https://e2e.ti.com/support/processors/f/791/t/771421

    Regards.
    Pavel

  • If you are using latest PSDK v6.01 (kernel 4.19.59), you will need to use:

     - compatible = "spidev";

    +  compatible = "rohm,dh2228fv";

    Check below file:

    linux-4.19.59/drivers/spi/spidev.c

    static const struct of_device_id spidev_dt_ids[] = {
        { .compatible = "rohm,dh2228fv" },
        { .compatible = "lineartechnology,ltc2488" },
        { .compatible = "ge,achc" },
        { .compatible = "semtech,sx1301" },
        {},
    };

  • Hy Pavel,

    Thanks for your response.
    I am using version 4.18.25-yocto-standard.
    Here is my spi info:

    spi0_pins_default: spi0_pins_default {
        pinctrl-single,pins = <
            AM33XX_IOPAD(0x950, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_22 (A17) spi0_sclk SCLK */
            AM33XX_IOPAD(0x958, PIN_INPUT_PULLUP  | MUX_MODE0)  /* P9_18 (B16) spi0_d1   MISO */
            AM33XX_IOPAD(0x954, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_21 (B17) spi0_d0   MOSI */
            AM33XX_IOPAD(0x95c, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_17 (A16) spi0_cs0  CS0  */    
            AM33XX_IOPAD(0x960, PIN_OUTPUT_PULLUP | MUX_MODE0) /* P9_16 (C15) spi0_cs1  CS1  */
        >;         };
        &spi0 {
                pinctrl-names = "default";
            pinctrl-0 = <&spi0_pins_default>;
            status = "okay";
            ti,spi-num-cs = <2>;
            ti,pindir-d0-out-d1-in = <1>;
        spidev@0 {
            compatible = "spidev";
            spi-max-frequency = <1000000>;
            reg = <0>;    //chipselect 0
            spi-cpol = <0>;
            spi-cpha = <1>; };
     
        spidev@1 {
            compatible = "adi,adis16400";
            spi-max-frequency = <1000000>;
            reg = <1>;    //chipselect 1  
            spi-cpol = <1>;
            spi-cpha = <1>; };};

    I also tried out with compatible = "rohm,dh2228fv";
    But this seems not working as well.

    Kind Regards,
    Amod

  • Amod,

    Amod Amatya said:
    I am using version 4.18.25-yocto-standard.

    From where you get this linux kernel? I would suggest you to try with the kernel that comes with AM335x TI PSDK Linux:

    http://software-dl.ti.com/processor-sdk-linux/esd/AM335X/latest/index_FDS.html

    Amod Amatya said:
      AM33XX_IOPAD(0x950, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_22 (A17) spi0_sclk SCLK */

    You are still using spi_sclk as output only, while you should configure it as input/output. Check again Biser's reply.

    Amod Amatya said:
    compatible = "adi,adis16400";

    For using spidev, you need to have:

    compatible = "rohm,dh2228fv";

    Regards,
    Pavel

  • Hy Pavel,

    Thank you for your resposne.
    We are currently using yocto to create a Linux distribution, so I am getting this version. And yes

    Yes I have changed this:

    AM33XX_IOPAD(0x950, PIN_OUTPUT_PULLUP | MUX_MODE0)  /* P9_22 (A17) spi0_sclk SCLK */ 

    into

    AM33XX_IOPAD(0x950, PIN_INPUT_PULLUP | MUX_MODE0)  /* P9_22 (A17) spi0_sclk SCLK */


    and then it works absolutely fine for the IMU which is ADIS16400 which is connected to spidev@1. I am able to read the IMU data.


    However in spidev@0, I have connected an ADC, ADS1256, and for now I am just trying to read the chipID. But I am getting random values for this case. I have also tried out with 

    compatible = "rohm,dh2228fv";

    instead of

    compatible = "spidev";

    But still getting some randome values. I will also check this thread and update if this resolves the issue:
    https://e2e.ti.com/support/processors/f/791/t/771421

    Kind Regards, 
    Amod

  • Amod Amatya said:
    We are currently using yocto to create a Linux distribution, so I am getting this version.

    This might be intermediate unstable version of the linux kernel. I would suggest you to try with linux kernel that comes with TI PSDK Linux. This version is official, tested and validated.

    Regards,
    Pavel