User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Enable/disable SPI without raspi-config or reboot?

Tue Sep 03, 2019 1:38 am

The reason I want SPI enabled is because I connected an arduino to it via level shifters so I can upload code to it using avrdude and spi programmer mode. It works very nicely since rpi 0w has only a single USB port and I won't waste it on arduino usb bootloader.

The reason I want RPI SPI disabled is because I still want arduino to be SPI master and talk to an SPI memory module. If I don't disable RPI's SPI, I wonder what might happen when Arduino uses it to talk to the SPI memory module. Both arduino and SPI memory are on the 5V side of simple MOSFET level shifters. RPI is on 3.3V side.

I should probably add a pull-up resistor to SPI memory's CS line so that when RPI is uploading firmware to arduino, it won't cause the memory module to activate. I could use some I2C memory but they are slower. Thanks for your time!
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
rpdom
Posts: 15601
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Enable/disable SPI without raspi-config or reboot?

Tue Sep 03, 2019 6:58 am

sudo dtparam spi=on

sudo dtparam spi=off

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Enable/disable SPI without raspi-config or reboot?

Tue Sep 03, 2019 11:46 pm

Thanks! I'll give it a try.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
HermannSW
Posts: 1658
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Enable/disable SPI without raspi-config or reboot?

Wed Sep 04, 2019 9:22 am

rpdom wrote:
Tue Sep 03, 2019 6:58 am
sudo dtparam spi=on

sudo dtparam spi=off
Wow, I did not know about command line use of dtparam.

So each statement adds an overlay.

Code: Select all

[email protected]:~ $ grep spi /boot/config.txt 
dtparam=spi=on
[email protected]:~ $ sudo dtparam spi=off
[email protected]:~ $ grep spi /boot/config.txt 
dtparam=spi=on
[email protected]:~ $ dtparam -l
Overlays (in load order):
0:  dtparam  spi=off
[email protected]:~ $

But I think "dtparam -r" instead of 2nd command would be preferable:

Code: Select all

[email protected]:~ $ sudo dtparam spi=on
[email protected]:~ $ dtparam -l
Overlays (in load order):
0:  dtparam  spi=off
1:  dtparam  spi=on
[email protected]:~ $ sudo dtparam -r
[email protected]:~ $ dtparam -l
Overlays (in load order):
0:  dtparam  spi=off
[email protected]:~ $ 
[code]
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1658
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Enable/disable SPI without raspi-config or reboot?

Wed Sep 04, 2019 11:56 am

Perhaps not a good idea to use this feature, I found these two messages in "dmesg" output after above commands:

Code: Select all

[ 7371.068846] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/[email protected]/status
[ 7386.818890] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/[email protected]/status
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Enable/disable SPI without raspi-config or reboot?

Wed Sep 04, 2019 3:03 pm

I'm confused now as I'm not nix wiz. I'm not familiar with dtparam messages. What are loading orders and do the dtparam on or off work?
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
liudr
Posts: 685
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Enable/disable SPI without raspi-config or reboot?

Wed Sep 04, 2019 3:45 pm

Maybe I should just stick with hardware solution:
54AHCT125 quad buffer (3V->5V logic converter) with 3-state outputs. It has output enable. I can have two of them convert pi's MOSI, SCK, from 3V to 5V, along with GPIO25 to reset Arduino and TX (serial) to Arduino RX. On Arduino side, switch off OE on these first two pins after reset so Arduino can use these pins. Upon arduino reset, these OE are pulled low by a pulldown resistor to allow pi to use the pins to program arduino.

For MISO, I'll find a corresponding chip that does 5V-3V with OE so I can disconnect it from pi.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

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