Integrating with SD cards over Serial Peripheral Interface (SPI)
Serial Peripheral Interface (SPI) is another serial communication protocol that can be used with devices. The main difference is that SPI requires at least four signal lines and one more each time when adding a new device to the bus.
Figure 3.6: SPI architecture
In this figure, the master node provides a clock over the CLK line,uses the Master-Out-Slave-In (MOSI) line to send data, and receives data over the Master-In-Slave-Out (MISO) line. It can communicate with a single slave node at a time. To select a slave node, it pulls the corresponding Chip-Select (CS) line to low.
Although SPI consumes more pin resources on an MCU, it achieves a higher data transfer rate compared to I2C. Therefore, in some applications, such as where SD-card integration is needed, it makes sense to prefer the SPI protocol over I2C.
In the next example, we will add SD card storage to our ESP32-C3-DevKitM-1 development kit...