Page 1 of 1

GPIO Alternate Functions

Posted: Thu May 16, 2019 6:50 pm
Hi all!

I faced strange behavior of alternate pins functions.
So, I have enabled SPI.

Code: Select all

set it up to alternative pins

Code: Select all

also tested this setting up

Code: Select all

sudo raspi-gpio set 35 a0
sudo raspi-gpio set 36 a0
sudo raspi-gpio set 37 a0
sudo raspi-gpio set 38 a0
sudo raspi-gpio set 39 a0
and this

Code: Select all

gpio -g mode 36 alt5
gpio -g mode 37 alt5
gpio -g mode 38 alt5
gpio -g mode 39 alt5

Tried to work with it through spidev python module (pip install spidev).

Everything good except one. CS always high. CS1 and CS0 (I am using only CS0).

I tested with simple python code listed below

Code: Select all

    spi = spi.SpiDev(), 0)
    spi.max_speed_hz = 976000
    spi.mode = 0b00

    while True:
        result = spi.xfer2([0x44, 0xBB], 976000, 80)
After that I used it with moving to alternate functions.

Everything fine.

So, as i understand both CS did not move to alt functions.Is this problem with my CM3 or may be with main board?

Thanks in advance for your replies

Re: GPIO Alternate Functions

Posted: Thu May 16, 2019 8:11 pm
by joan
I'm not sure what you are worried about. It is not clear if CS is being toggled properly or not.

As far as the mode it will be set to mode OUTPUT by the kernel driver. The current kernel driver takes care of setting CS high/low in software. It only needs to be in an ALT mode if the SPI hardware is used to control CS.