Configuration Parameter |
Selectable Option/Value |
Description |
Chip select pin (CS) |
0 to 33 |
Select pin for CS |
Clock pin (SCLK) |
0 to 33 |
Select pin for SCLK |
Master read (MISO) |
0 to 33 |
Select pin for MISO |
Master write (MOSI) |
0 to 33 |
Select pin for MOSI |
Format if mount fail |
True--False |
If FAT partition cannot be mounted, and this parameter is true, create the partition table and format the filesystem. |
Base path |
|
The block registers given FAT drive in VFS, at the specified base path. |
Maximum number of files |
|
maximum number of files which can be open at the same time |
Allocation unit size |
|
If ‘format_if_mount_failed’ is set, and mount fails, format the card with the given allocation unit size. Must be a power of 2, between sector size and 128 * sector size. For SD cards, sector size is always 512 bytes. |
Configuration Parameter |
Selectable Option/Value |
Description |
Output data buffer size |
32--64--128--256--512--1024--2048--4096 |
Select the expected number of characters to be read from SD card file. |
File path |
|
The file path should follow the following convention /<Base path>/<filename>.<extention> |
INPUT/ OUTPUT Port
Port Name |
Port Type |
Date Type |
Description |
Data |
Vector |
uint8 |
The port outputs a character vector with the data written in the requested file in the SD card. |
Configuration Parameter |
Selectable Option/Value |
Description |
File path |
|
The file path should follow the following convention /<Base path>/<filename>.<extention> |
INPUT/ OUTPUT Port
Port Name |
Port Type |
Date Type |
Description |
Data |
Vector |
uint8 |
Feed in a character vector with the data to be written. |
Configuration Parameter |
Selectable Option/Value |
Description |
File path |
|
The file path should follow the following convention /<Base path>/<filename>.<extention> |
INPUT/ OUTPUT Port
Port Name |
Port Type |
Date Type |
Description |
Data |
Vector |
uint8 |
Feed in a character vector with the data to be appended. |
This block can be used to set up, read, write, append data to an SD card connected to an ESP32 microcontroller. For convenience, the driver is implemented on four blocks. Namely,
•SD Card Setup
•SD Card Read
•SD Card Write
•SD Card Append
It is mandatory to have the SD Card Setup block present in the model whenever the other blocks are used.
•SD Card Setup: ESP-IDF uses the FatFs library to work with FAT filesystems. FatFs reside in the fatfs component.
•SD Card Read: The block reads the content saved in the specified file up to the buffer size limit and outputs the data from the output port.
•SD Card Write: The block search for the file name in the given path. If the filename already exists, it deletes that file and creates a new file with the same name, and writes the new data to that file. If the file name does not exist, it creates a new file and the data.
•SD Card Append: The block search for the file name in the given path. If the file name already exists, it opens that file and adds the new data to the file. If the file name does not exist, it creates a new file and the data.
Demo file : esp32_sdcard_demo.slx
This demo shows how to use the SD card block. In the model, the SENSORS subsystem is used to mimic two analog sensors. Each second the acquired data is logged into a CSV file on the SD card.
Once the SD card is inserted into the target module and the program is uploaded, the data will be logged to the sd card. After about 10 seconds, remove the SD card and plug it into a Desktop or Laptop computer to view the data from the data.csv file created by the program.