Notice that we set all of the CS lines that SPI0 supports but only use CS0. We could include the setting up of the GPIO lines in the spi_init function, but doing it this way allows the selection of which CS lines to initialize within the user program.
In chapter but not in this extract
The MCP3008
Connecting to the Pi
Basic Configuration
The Protocol
MCP3008 in Gpio5
How Fast
The MCP3008 Driver
Problems
Summary
The Pi 5 has six SPI controllers but not all can be used at the same time.
Making SPI work with any particular device has four steps:
Discover how to connect the device to the SPI pins. This is a matter of identifying pinouts and what chip selects are supported.
Find out how to configure the Pi's SPI bus to work with the device. This is mostly a matter of clock speed and mode.
Identify the commands that you need to send to the device to get it to do something and what data it sends back as a response.
Find, or work out, the relationship between the raw reading, the voltage, and the quantity the voltage represents.
The Linux SPI driver can be used to interface to any SPI device as long as you know what commands to send and what the data sent back means.
The SPI driver is supported by the SPIdev header which provides the basic tools to work with the ioctl interface.
The SPI driver uses general GPIO lines as chip select lines and not the built-in hardware.
The hardware SPI controllers are based on Synopsys DW_apb_ssi and this is well documented.
It is easy to extend Gpio5 to work with SPI with many advantages.
Using the other SPI interfaces on the Pi 5 is just a matter of selecting the appropriate driver.
The MCP3000 range of A-to-D converters is very easy to use via SPI. It can be used directly from the SPI bus by sending commands and reading the data generated.
There is also a specific MCP3008 driver which allows you to work with the device without having to know anything about SPI or the commands that have to be sent to read the data.
The MCP3008 driver is an example of an IIO device.
You can find the complete Gpio5 at its Github repo:
Microsoft has released the source code of Basic 1.1 for the 6502 microprocessor on GitHub. The page with the code says the assembly language source code represents one of the most historically signifi [ ... ]