astirfreak
Posts: 15
Joined: Sat Nov 18, 2017 4:11 pm

SPI1 works, but CS0 not

Sat Jan 27, 2018 4:34 pm

Hi,
I have PI2+, with a working waveshare display clone. To control a second SPI device (potentiometer) I like to use SPI1.
In the config.txt I added

Code: Select all

dtoverlay=spi1-1cs
To control the SPI, I use Python with spidev.
My testcode is:

Code: Select all

import spidev
spi = spidev.SpiDev()
spi.open(1,0)
spi.max_speed_hz=50000
spi.cshigh=False 			# |
spi.cshigh=True 			# -> No effect if one of this lines is used
spi.xfer([0xAA])
spi.close()
I can see clock on DCLK (Pin 40) and data an MOSI (Pin 38).
On pin 36 (SPI1_CS0) I cannot see anything. It has a constant low level.

To check, if there is a hardware problem I tried:

Code: Select all

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(16, GPIO.OUT)	
GPIO.output(16,1)
With that code I can see, the pin 36 (GPIO16) is working.

Whats wrong here?

Michael

astirfreak
Posts: 15
Joined: Sat Nov 18, 2017 4:11 pm

Re: SPI1 works, but CS0 not

Sat Jan 27, 2018 5:01 pm

Code: Select all

dtoverlay=spi-gpio35-39
doesn't work for me.
The display then doesn't work anymore and no spi is visible in /dev

astirfreak
Posts: 15
Joined: Sat Nov 18, 2017 4:11 pm

Re: SPI1 works, but CS0 not

Sat Jan 27, 2018 5:20 pm

Further findings:
https://pinout.xyz/pinout/spi#
It uses the CS0 on Pin12 (GPIO18). I can see it on this pin with my oscilloscope.

Pin 36 isn't CS0 for SP1 as mentioned in
Image

Pin 12 is blocked by the display.
To use Pin 36 instead I have to create an own overlay. Now I have to google how to do that.

Michael

astirfreak
Posts: 15
Joined: Sat Nov 18, 2017 4:11 pm

Re: SPI1 works, but CS0 not

Sat Jan 27, 2018 5:35 pm

Does anyone know, where to find the original code of spi1-1cs.dtbo?
I only find the precompiled versions but I want to modify it and compile it by myself.

Michael

ericcooper
Posts: 76
Joined: Sat Apr 08, 2017 6:23 pm

Re: SPI1 works, but CS0 not

Sat Jan 27, 2018 6:13 pm

It's in arch/arm/boot/dts/overlays/ on https://github.com/raspberrypi/linux, rpi-4.9.y branch

astirfreak
Posts: 15
Joined: Sat Nov 18, 2017 4:11 pm

Re: SPI1 works, but CS0 not

Sat Jan 27, 2018 7:34 pm

Thank you, now I got it working:

Code: Select all

/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

        fragment@0 {
                target = <&gpio>;
                __overlay__ {
                        spi1_pins: spi1_pins {
                                brcm,pins = <19 20 21>;
                                brcm,function = <3>; /* alt4 */
                        };

                        spi1_cs_pins: spi1_cs_pins {
                                brcm,pins = <16>;
                                brcm,function = <1>; /* output */
                        };
                };
        };

        fragment@1 {
                target = <&spi1>;
                frag1: __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;
                        pinctrl-names = "default";
                        pinctrl-0 = <&spi1_pins &spi1_cs_pins>;
                        cs-gpios = <&gpio 16 1>;
                        status = "okay";

                        spidev1_0: spidev@0 {
                                compatible = "spidev";
                                reg = <0>;      /* CE0 */
                                #address-cells = <1>;
                                #size-cells = <0>;
                                spi-max-frequency = <125000000>;
                                status = "okay";
                        };
                };
        };

        fragment@2 {
                target = <&aux>;
                __overlay__ {
                        status = "okay";
                };
        };

        __overrides__ {
                cs0_pin  = <&spi1_cs_pins>,"brcm,pins:0",
                           <&frag1>,"cs-gpios:4";
                cs0_spidev = <&spidev1_0>,"status";
        };
I only replaced the two entrys of the CS-Pin from 18 to 16.

If the the device tree compiler is not installed it has to be installed:

Code: Select all

sudo apt-get install device-tree-compiler
After that I compiled my dts:

Code: Select all

 dtc -@ -I dts -O dtb -o spi1-1cs36.dtbo spi1-1cs36.dts 
                    
spi1-1cs36.dtbo: Warning (unit_address_vs_reg): Node /fragment@0 has a unit name, but no reg property
spi1-1cs36.dtbo: Warning (unit_address_vs_reg): Node /fragment@1 has a unit name, but no reg property
spi1-1cs36.dtbo: Warning (unit_address_vs_reg): Node /fragment@2 has a unit name, but no reg property
I got that warnings but I ignored it.

Now the dtbo has to be copied:

Code: Select all

sudo cp spi1-1cs36.dtbo /boot/overlays
The last step is to add it to the boot.cfg:

Code: Select all

sudo nano /boot/config.txt
And here I added a new entry as last line:

Code: Select all

dtoverlay=spi1-1cs36

vybhav
Posts: 1
Joined: Thu Mar 22, 2018 7:15 am

Re: SPI1 works, but CS0 not

Thu Mar 22, 2018 7:19 am

Hi
I made the above changes (dtoverlay=spi1=1cs) in the config.txt.
In the program when i wrote spi.open(1,0) i am getting an error "[Errorno2] no such file or directory "
can anyone help me out in using spi1(python code)

Thank you

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 3 guests