All,
I have searched the forum but I am still not able to get to the bottom of this.
1.) Is it possible to reconfigure pins CE0 and CE1 to be outputs instead of inputs and use them as regular GPIOs?
2.) Is it possible to reconfigure the SPI pins that are showing up as MOSI, MISO and SCLK as outputs and use and GPIOs?
I am using the gpio utility but don't seem to be able to change the state of these pins.
Thanks.
-Mike
-
- Posts: 38
- Joined: Wed Mar 29, 2017 11:42 pm
Re: Re-purposing SPI lines to be GPIOs?
Yes. All the GPIO are GPIO. Unless you have asked for a GPIO to be in a special mode (e.g. by a device tree setting) it will be in INPUT mode. All GPIO may be set to be in INPUT mode and in OUTPUT mode. Read the documentation of the utility you are using.
E.g. http://abyz.co.uk/rpi/pigpio/pigs.html#M/MODES
E.g. http://abyz.co.uk/rpi/pigpio/pigs.html#M/MODES
-
- Posts: 3161
- Joined: Tue Jan 19, 2016 2:17 pm
- Location: Sydney, Nova Scotia, Canada
Re: Re-purposing SPI lines to be GPIOs?
Check your Raspberry Pi Configuration menu > Interfaces. You may have to turn some things off (disable) to get full control. I only enable what I know I need like I2C etc.
-
- Posts: 38
- Joined: Wed Mar 29, 2017 11:42 pm
Re: Re-purposing SPI lines to be GPIOs?
Seems strange..
It is working now with
$ gpio mode [gpio #] output
Thanks.
It is working now with
$ gpio mode [gpio #] output
Thanks.
-
- Posts: 38
- Joined: Wed Mar 29, 2017 11:42 pm
Re: Re-purposing SPI lines to be GPIOs? (Ras. Pi 3)
Hello everyone.
1.) What I have been doing to configure a GPIO "0" pin to be an output is the following:
gpio mode 0 output
Then to set the GPIO 0 to high the following:
gpio write 0 1
2.) When I do a gpio readall the MOSI (Physical pin 19 of the 40 pin connector) and MISO (Physical pin 21 of the 40 pin connector) pins don't show the GPIO number they are. I don't know how to use the gpio command if I don't know the GPIO #.
3.) I am not able to reconfigure these pins to be an output with the GPIO command. I disabled the SPI interface using raspi-config and this is still not working for me.
Thank you for an tips.
-Mike
1.) What I have been doing to configure a GPIO "0" pin to be an output is the following:
gpio mode 0 output
Then to set the GPIO 0 to high the following:
gpio write 0 1
2.) When I do a gpio readall the MOSI (Physical pin 19 of the 40 pin connector) and MISO (Physical pin 21 of the 40 pin connector) pins don't show the GPIO number they are. I don't know how to use the gpio command if I don't know the GPIO #.
3.) I am not able to reconfigure these pins to be an output with the GPIO command. I disabled the SPI interface using raspi-config and this is still not working for me.
Thank you for an tips.
-Mike
Re: Re-purposing SPI lines to be GPIOs?
What does gpio readall show for you then? It shows the full details of those pins for me.
MOSI: GPIO 10/Pin 19/WiringPi 12
MISO: GPIO 9/Pin 21/Wiring Pi 13
Code: Select all
pi@raspi8:~ $ gpio readall
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 0 | IN | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
MISO: GPIO 9/Pin 21/Wiring Pi 13
-
- Posts: 38
- Joined: Wed Mar 29, 2017 11:42 pm
Re: Re-purposing SPI lines to be GPIOs?
Hello.
When I start off with a gpio readall here is what I get:
Note how MOSI is on the physical pin 19 and MISO is on the physical pin 21.

You can see the result when I do
gpio mode 10 output
gpio mode 11 output
This is actually changes the port direction for CE0 and CE1 that are on GPIO 10 and GPIO 11. MISO and MOSI remain unchanged.

Thanks for any thoughts.
-Mike
When I start off with a gpio readall here is what I get:
Note how MOSI is on the physical pin 19 and MISO is on the physical pin 21.

You can see the result when I do
gpio mode 10 output
gpio mode 11 output
This is actually changes the port direction for CE0 and CE1 that are on GPIO 10 and GPIO 11. MISO and MOSI remain unchanged.

Thanks for any thoughts.
-Mike
- DougieLawson
- Posts: 42636
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Re-purposing SPI lines to be GPIOs?
Don't load the SPI driver module. There's a line item in /boot/config.txt for that. There's an option in the settings widget (and in sudo raspi-config) to disable SPI.
Languages using left-hand whitespace for syntax are ridiculous
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.
The use of crystal balls and mind reading is prohibited.
-
- Posts: 38
- Joined: Wed Mar 29, 2017 11:42 pm
Re: Re-purposing SPI lines to be GPIOs?
I did run the raspi-config and in my boot config there is an entry already to disable SPI:
/boot/config.txt
.....
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=off
I am still having the same problem.
-Mike
/boot/config.txt
.....
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=off
I am still having the same problem.
-Mike
-
- Posts: 38
- Joined: Wed Mar 29, 2017 11:42 pm
Re: Re-purposing SPI lines to be GPIOs?
Does anyone have any ideas on this? I am totally stuck.
Thank you.
-Mike
Thank you.
-Mike
Re: Re-purposing SPI lines to be GPIOs?
Many of the functions of the "gpio" binary expect wiringPi pin numbering by default.
Use "gpio -g mode 10 output" to indicate that you mean Broadcom numbering.
Use "gpio -g mode 10 output" to indicate that you mean Broadcom numbering.
-
- Posts: 38
- Joined: Wed Mar 29, 2017 11:42 pm
Re: Re-purposing SPI lines to be GPIOs?
Thank you jojopi.
This fixed my problem.
Have a nice day!
-Henk
This fixed my problem.
Have a nice day!
-Henk
Re: Re-purposing SPI lines to be GPIOs?
I always assumed that CE0 and CE1 were outputs anyway
Texy

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555
Re: Re-purposing SPI lines to be GPIOs?
I'm well aware that this thread is an old one, but my question is closely related to it...
1- I actually am using SPI on my Raspberry so I have dtparam=spi=on
2- I am using BCM-GPIO-21 (PIN 40 on my Raspberry 3 Model B+) as an input pin for other purposes.
Now, I learned that this GPIO is intended to be used for a second SPI channel, according to
https://pinout.xyz/.
So I wonder whether the SPI driver might interfere with my application connected to BCM-GPIO-21, which indeed sometimes gets questionable impulses.
Is there a way to load the SPI driver for SPI0, but make sure it won't try to use the pins associated with SPI1?
And yes, it would require a major redesign to use another GPIO pin for my application...
Thanks for any suggestions,
Alex
1- I actually am using SPI on my Raspberry so I have dtparam=spi=on
2- I am using BCM-GPIO-21 (PIN 40 on my Raspberry 3 Model B+) as an input pin for other purposes.
Now, I learned that this GPIO is intended to be used for a second SPI channel, according to
https://pinout.xyz/.
So I wonder whether the SPI driver might interfere with my application connected to BCM-GPIO-21, which indeed sometimes gets questionable impulses.
Is there a way to load the SPI driver for SPI0, but make sure it won't try to use the pins associated with SPI1?
And yes, it would require a major redesign to use another GPIO pin for my application...
Thanks for any suggestions,
Alex
Re: Re-purposing SPI lines to be GPIOs?
There should be no interference between the main and auxiliary SPI GPIO. The auxiliary SPI has to be separately enabled and they are driven by different hardware peripherals.
Check the mode of the auxiliary SPI GPIO, they are likely all to be inputs unless you have set them differently,
Check the mode of the auxiliary SPI GPIO, they are likely all to be inputs unless you have set them differently,
Re: Re-purposing SPI lines to be GPIOs?
Thanks for the clarification, that indeed helps!
-
- Posts: 22
- Joined: Wed Jun 05, 2013 6:42 am
- Location: Corvallis, OR
Re: Re-purposing SPI lines to be GPIOs?
I am having similar problem, maybe someone can help?
My build works fine using Jessie, I am in the process of updating to Buster and one thing does not work.
I am using SPI to connect to MCP3008 ADC chip. It is wired to GPIO 10,9,11, and GPIO8 for SPIO_CE0.
I need every pin on the RPi, so I am using GPIO7 as an input pin and wiringPiISR to set a callback.
On Buster, when I run the program, when I try to set GPIO7 as an input pin, I get this error:
The code is in C++ using wiringPi.
How can I use GPIO7 as a regular pin while also using SPI (with GPIO8 connected to SPIO_CEO) on Raspbian Buster. It worked on Jessie without any problem.
Thank you
My build works fine using Jessie, I am in the process of updating to Buster and one thing does not work.
I am using SPI to connect to MCP3008 ADC chip. It is wired to GPIO 10,9,11, and GPIO8 for SPIO_CE0.
I need every pin on the RPi, so I am using GPIO7 as an input pin and wiringPiISR to set a callback.
On Buster, when I run the program, when I try to set GPIO7 as an input pin, I get this error:
Code: Select all
gpio: Unable to open GPIO direction interface for pin 7: No such file or directory
wiringPiISR: unable to open /sys/class/gpio/gpio7/value: No such file or directory
How can I use GPIO7 as a regular pin while also using SPI (with GPIO8 connected to SPIO_CEO) on Raspbian Buster. It worked on Jessie without any problem.
Thank you