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 DualMCU ONE 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-C6.

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-C6

Table 4 HSPI Connections#

SD Card

ESP32C6

PIN

D2

D3

SS (Slave Select)

19

CMD

MOSI

7

VSS

GND

VDD

3.3V

CLK

SCK (Serial Clock)

6

VSS

GND

D0

MISO

2

D1

import machine
import os
from sdcard import SDCard

# Definir pines para SPI y SD
MOSI_PIN = 7
MISO_PIN = 2
SCK_PIN = 6
CS_PIN = 19

# 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"))