Initialization

Before start using the SD card, it needs to be initialized. This process checks if an SD card is present on the slot, initializes SPI bus, opens partition and opens root directory.

Initializing a card

The following function checks if an SD card is present in the slot, sets the microcontroller pin which powers the SD card up, initializes the SPI bus, opens the FAT volume partition and opens the root directory. It returns nothing but it updates the flag with an error code indicating the possible error messages.

Example of use

{
 SD.ON(); // Set SD card on
 }

Available Information

SD.flag → stores the error code indicating the state of SD initialization process.

The SD card cannot be removed or inserted without powering off Waspmote. If a SD card is removed, the initialization function should be called to initialize the card again. Before that, the SD Card should be closed using functions explained in section “Closing a card”.

Closing a card

Closes the root directory and the SPI bus. It also switches off the microcontroller pin that powers the SD card. It returns nothing and it does not change the flag value.

Example of use

{
 SD.OFF(); // Powers SD card down
 }

SD present

It reads the associated pin to know if there is an SD in card slot.

It returns ‘1’ if SD card is present and ‘0’ if not.

If SD is not present, it closes card to avoid problems with pointers.

Example of use

{
 uint8_t present;
 // Reads associated pin to know if there is a SD in card slot
 present=SD.isSD();
 }

Available Information

present→ stores ‘1’ if SD card is detected and ‘0’ if not.

Last updated