Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4907

Advanced users • Re: Sharing SPI Bus with ENC28J60 & MCP3008 on RPi 3 B+

$
0
0
The CS pins for each SPI interfaces are declared in Device Tree. The defaults are GPIO8 and GPIO7 for SPI0.0 and SPI0.1. You can change them using a dtoverlay:

Code:

$  dtoverlay -a | grep -E "spi[0-9]-[0-9]"  spi0-0cs  spi0-1cs  spi0-2cs  spi0-3cs  spi1-1cs  spi1-2cs  spi1-3cs  spi2-1cs  spi2-1cs-pi5  spi2-2cs  spi2-2cs-pi5  spi2-3cs  spi3-1cs  spi3-1cs-pi5  spi3-2cs  spi3-2cs-pi5  spi4-1cs  spi4-2cs  spi5-1cs  spi5-1cs-pi5  spi5-2cs  spi5-2cs-pi5  spi6-1cs  spi6-2cs$ dtoverlay -h spi0-2csName:   spi0-2csInfo:   Change the CS pins for SPI0Usage:  dtoverlay=spi0-2cs,<param>=<val>Params: cs0_pin                 GPIO pin for CS0 (default 8)        cs1_pin                 GPIO pin for CS1 (default 7)        no_miso                 Don't claim and use the MISO pin (9), freeing                                it for other uses.
So to enable SPI0 (which uses GPIOs 9-11), with 2 CS lines on GPIOs 3 and 4, put the following in config.txt:

Code:

dtoverlay=spi0-2cs,cs0_pin=3,cs1_pin=4
Note that although you'll see many DT parameters called "something-pin", they are actually GPIO numbers. In my example, GPIO 3 is on pin 5 and GPIO 4 is on pin 7. The pinctrl utility can help you find thiungs on the 40-pin header:

Code:

$ pinctrl -p 1: 3v3 2: 5v 3: a3    pu | hi // GPIO2 = SDA1 4: 5v 5: a3    pu | hi // GPIO3 = SCL1 6: gnd 7: no    pu | -- // GPIO4 = none 8: no    pd | -- // GPIO14 = none 9: gnd10: no    pd | -- // GPIO15 = none11: op dh pd | hi // GPIO17 = output12: op dh pd | hi // GPIO18 = output13: no    pd | -- // GPIO27 = none14: gnd15: no    pd | -- // GPIO22 = none16: no    pd | -- // GPIO23 = none17: 3v318: no    pd | -- // GPIO24 = none19: a0    pn | lo // GPIO10 = SPI0_MOSI20: gnd21: a0    pn | lo // GPIO9 = SPI0_MISO22: no    pd | -- // GPIO25 = none23: a0    pn | lo // GPIO11 = SPI0_SCLK24: op dh pu | hi // GPIO8 = output25: gnd26: op dh pu | hi // GPIO7 = output27: ip    pu | hi // GPIO0 = input28: ip    pu | hi // GPIO1 = input29: no    pu | -- // GPIO5 = none30: gnd31: no    pu | -- // GPIO6 = none32: no    pd | -- // GPIO12 = none33: no    pd | -- // GPIO13 = none34: gnd35: a0    pd | lo // GPIO19 = SPI1_MISO36: op dh pd | hi // GPIO16 = output37: no    pd | -- // GPIO26 = none38: a0    pd | lo // GPIO20 = SPI1_MOSI39: gnd40: a0    pd | lo // GPIO21 = SPI1_SCLK

Statistics: Posted by PhilE — Fri Mar 22, 2024 12:47 pm



Viewing all articles
Browse latest Browse all 4907

Trending Articles