SPI (Serial Peripheral Interface)

SPI (Serial Peripheral Interface)#

SPI Overview#

SPI (Serial Peripheral Interface) is a synchronous, full-duplex, master-slave communication bus. It is commonly used to connect microcontrollers to peripherals such as sensors, displays, and memory devices. The TouchDot development board features SPI communication capabilities, allowing you to interface with a wide range of SPI devices.

SDCard SPI#

Warning

Ensure that the Micro SD contain data. We recommend saving multiple files beforehand to facilitate the use. Format the Micro SD card to FAT32 before using it with the ESP32-S3.

Micro SD Card Pinout

Fig. 16 Micro SD Card Pinout#

Micro SD Card reader

Fig. 17 Micro SD Card external reader#

The conections are as follows:

This table illustrates the connections between the SD card and the GPIO pins on the ESP32-S3

Table 11 microSD Connector (SPI Mode)#

Pin

microSD Pin Name

SPI Function

ESP32-S3 GPIO

GPIO Function

Type

1

DAT2

Not used in SPI

2

CD / DAT3

CS (Chip Select)

GPIO21

RTC_GPIO2, GPIO21

I/O/T

3

CMD

MOSI

GPIO9

RTC_GPIO9, TOUCH9, ADC1_CH8, FSPIHD, SUBSPIHD

I/O/T

4

VDD

3.3V

3.3V

Power Supply

P

5

CLK

SCLK

GPIO7

RTC_GPIO7, TOUCH7, ADC1_CH6

I/O/T

6

VSS

GND

GND

Ground

GND

7

DAT0

MISO

GPIO8

RTC_GPIO8, TOUCH8, ADC1_CH7, SUBSPICS1

I/O/T

8

DAT1

Not used in SPI

import machine
import os
from sdcard import SDCard

# Definir pines para SPI y SD
MOSI_PIN = 9
MISO_PIN = 8
SCK_PIN = 7
CS_PIN = 21

# Inicializar SPI
spi = machine.SPI(1, baudrate=500000, polarity=0, phase=0,
                  sck=machine.Pin(SCK_PIN),
                  mosi=machine.Pin(MOSI_PIN),
                  miso=machine.Pin(MISO_PIN))

# Inicializar tarjeta SD
sd = SDCard(spi, machine.Pin(CS_PIN))

# Montar la SD en el sistema de archivos
os.mount(sd, "/sd")

# Listar archivos y directorios en la SD
print("Archivos en la SD:")
print(os.listdir("/sd"))