Enable and disable the SPI interface on the Raspberry Pi kernel and use the Raspberry Pi hardware board pins for SPI functionality and GPIO, respectively. Write and read
data from the EEPROM SPI IC 25AA080 interfaced with the Raspberry Pi hardware board and exchange data. For more information on IC 25AA080, refer to
its datasheet. You can also exchange data between the Raspberry Pi and other SPI devices. For more information, refer to the datasheet of the
specific SPI device. Perform these steps on the Raspberry Pi
Linux® terminal to ensure that the SPI interface is enabled in the hardware
kernel.
Run this command:
Select Interfacing Options > SPI.
Select Yes when prompted to enable the SPI interface.
Select Yes when prompted to automatically load the SPI kernel
module.
Select Finish.
Select Yes when prompted to reboot.
To create a connection from MATLAB to the Raspberry Pi board, execute this command at the MATLAB Command
Window.
DeviceAddress: 'raspberrypi-hysdu8X38o'
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'}
I2CBusSpeed: 100000
AvailabelWebCams: mmal service 16.1 (platform:bcm2835-v4l2)
GPIO
header pins
MISO (GPIO 9)
,
MOSI (GPIO 10)
, and
SCLK (GPIO 11)
are used for SPI functionality. GPIO pins 9, 10, and
11 are not listed in the
AvailableDigitalPins
property as the SPI
functionality is enabled by default and the pins are currently being utilized by the SPI
functionality.
To display the pin mapping of the Raspberry Pi hardware board, execute this command at the MATLAB Command Window.
The revised pin map of the Raspberry Pi hardware board shows the location of the SPI pins, SPI_MISO (GPIO
9)
, SPI_MOSI (GPIO 10)
, and SPI_SCLK (GPIO
11)
, on the CE1
bus.
After physically connecting your SPI device to the three SPI pins of the Raspberry Pi hardware board, establish a connection to the SPI device through the
CE1
bus.
eeprom =
spidev with properties:
Channel: CE1
Mode: 0
BitsPerWord: 8
Speed: 500000
Enable write and read operation on
EEPROM.
Write data to EEPROM with the precision of
uint8
.
dataOut =
1×6 uint8 row vector
0 0 0 0 0 0
Read data from EEPROM with the precision of uint8
.
dataOut =
1×6 uint8 row vector
0 0 0 1 2 3
Clear the active SPI device connection before disabling it. After you disable the SPI
functionality, you can use the Raspberry Pi hardware board pins as GPIO
pins.
DeviceAddress: 'raspberrypi-hysdu8X38o'
Port: 18734
BoardName: 'Raspberry Pi 3 Model B+'
AvailableLEDs: {'led0'}
AvailableDigitalPins: [4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27]
AvailableSPIChannels: {}
AvailableI2CBuses: {'i2c-1'}
I2CBusSpeed: 100000
AvailabelWebCams: mmal service 16.1 (platform:bcm2835-v4l2)
The
GPIO 7, 8, 9, 10,
and
11
pins are now available
and can be used as GPIO pins. No SPI buses are available for SPI interfacing.
Before using SPI again, enable the SPI
functionality.