This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

disableSPI

Disable SPI interface

Syntax

disableSPI(mypi)

Description

example

disableSPI(mypi) disables the SPI bus and frees the pins for use as GPIO pins. By default, SPI is disabled. This method works only after you use enableSPI.

For example, on a Raspberry Pi™ Model B Rev 2 board, disabling the SPI bus frees the GPIO 10 (SPI0_MOSI), GPIO 9 (SPI0_MISO), and GPIO 11 (SPI0_SCLK) pins.

Examples

collapse all

You can connect to and exchange data with an SPI device.

Create a connection from the MATLAB® software to the Raspberry Pi board.

mypi = raspi
r = 

  raspi with properties:

         DeviceAddress: '172.18.188.249'              
                  Port: 18734                         
             BoardName: 'Raspberry Pi 3 Model B+'     
         AvailableLEDs: {'led0'}                      
  AvailableDigitalPins: [4,5,6,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]
  AvailableSPIChannels: {'CE0','CE1'}                 
     AvailableI2CBuses: {'i2c-1'}                     
      AvailableWebcams: {}                            
           I2CBusSpeed: 100000                        

  Supported peripherals

By default, SPI is enabled. If SPI is disabled, AvailableSPIChannels does not show any channels.

Enable SPI and get the channels by using enableSPI.

enableSPI(mypi)
mypi.AvailableSPIChannels
ans = 

    'CE0'    'CE1'

Show the location of the SPI pins, GPIO 10 (SPI0_MOSI), GPIO 9 (SPI0_MISO), and GPIO 11 (SPI0_SCLK), on the GPIO header.

showPins(mypi)

After physically connecting your SPI device to the three SPI pins, connect to the SPI device.

myspidevice = spidev(mypi,'CE1',0)
myspidevice = 

Spidev with Properties:
           Channel: 'CE1'
              Mode: 0 
       BitsPerWord: 8
             Speed: 500000

Write data to, and read data from, the SPI device.

out = writeRead(myspidevice,[hex2dec('08') hex2dec('D4')])
out = 
         7 211

If you are not using SPI, disable SPI to make additional GPIO pins available.

disableSPI(mypi)

Input Arguments

collapse all

Connection to a specific Raspberry Pi hardware board, specified as a raspi object.