Demonstrating Secure Digital Flash Memory Card Functionality Using MPLAB® Code Configurator (MCC)

Last modified by Microchip on 2023/11/10 11:17

Objective

This tutorial demonstrates how to add microSD card functionality to a new MPLAB® X Integrated Development Environment (IDE) project. MPLAB Code Configurator (MCC) is used to configure peripheral drivers such as Universal Asynchronous Receiver-Transmitter (UART), Serial Peripheral Interface (SPI) and the File System Library.

Overview

This tutorial makes use of Mikroe’s microSD Click board™, MCP2221A Breakout Module and PIC24FJ256GA7 Curiosity Development Board to simplify hardware integration.

Additionally, this tutorial showcases the capability of the File System Library to provide SD/MMC Flash memory card support and file system functionality to a new MPLAB X IDE project.

Microchip Technology’s File System Library is a generic File Allocation Table (FAT) file system developed by a third party and made available through an open-source license. It will be used to interface a microSD card via the microSD Click board. It features a DOS/Windows compatible FAT file system, a small footprint, and various configuration options to support long file names, multiple volumes, variable sector size, multiple code pages, and more. It also provides file system functionality that includes open/create, close, read, write, move, and many more operations. For more details about the features of the File System Library, refer to the FatFs – Generic FAT File System User Guide.

MCC is a free graphical programming environment that generates seamless, easy-to-understand C code that is inserted into your project. It enables and configures a rich set of peripherals and functions using an intuitive interface. It is integrated into MPLAB X IDE to provide a powerful and easy-to-use development platform.

The application verifies a card is present; registers, creates, and opens a file; writes and reads data; then closes the file; and unmounts the drive. 

Secure Digital Flash Memory Card Flowchart

The application is based on a state machine that uses a simple switch statement placed in an infinite loop in the main function.

If an error occurs, a message is printed to the terminal using the UART peripheral. The application will then place the state machine into an idle state.

This application utilizes:

  • UART1 for terminal communication
  • SPI1 for SD/MMC card data
  • General Purpose Inputs/Outputs (GPIO) for SD/MMC card control

In addition, the application utilizes a virtual communication port for user input and information output.

Two Ways to Use This Tutorial

  • Use the solution project as an example:
  • Build the solution project, microSD-app-pic24fjxxxga7-solution, and program it to the PIC24FJ256GA7 Curiosity board to observe the expected behavior.
  • Follow the lab procedure:
  • Open the lab project, microSD-app-pic24fjxxxga7-lab, follow the lab procedure and MCC will add the missing files to complete the project.

Lab Objectives

  • Install the MPLAB X IDE MCC project for a PIC24FJ256GA705 microcontroller.
  • Use MCC to configure and generate peripheral libraries (PLIB) code for the following peripherals:
  • SPI
  • UART
  • GPIO
  • Use MCC Peripheral Library (PLIB) Application Programming Interfaces (APIs) to implement the application.

Back to Top

Reference Materials

Note: The Curiosity series evaluation kits include an on-board, embedded debugger. No external tools are necessary to program or debug the PIC24FJ256GA705. For programming/debugging, the debugger connects to the host PC through the USB Micro-B connector on the PIC24FJ256GA7 Curiosity board.

Back to Top

Hardware Connection Setup

Secure Digital Flash Memory Card Demonstration Hardware Connection Setup

Apart from the hardware tools listed above, the following items are required:

  • USB Type-A male-to-Micro-B male cable
  • USB Type-A male-to-mini male cable
  • Four jumper wires

Back to Top

Connection Diagram

The application has the Mikroe microSD Click board connected to GPIO and SPI1 and MCP2221A breakout module connected to UART1.

Secure Digital Flash Memory Card Connection Diagram

Back to Top

Software Tools

Note: This project has been verified to work with the following versions of software tools:

  • MPLAB X IDE v5.50
  • MPLAB XC16 v1.70
  • MPLAB Code Configurator plugin v4.2.4
  • MPLAB Data Visualizer plugin v1.2.956
  • Microchip File System Library v1.1.0
  • File extraction utility such as 7-Zip that supports ZIP files

Because we regularly update our tools, occasionally you may discover an issue while using the newer versions. If you suspect that to be the case, we recommend that you double-check and use the same versions that the project was tested with.

Back to Top

Lab Source Files and Solutions

There are two ZIP files associated with this training:

1.  microSD-app-pic24fjxxxga7-solution: is the completed solution that can be programmed to demonstrate the lab and verify your setup.

2.  microSD-app-pic24fjxxxga7-lab: is the same project with the MCC files removed. It contains the source files needed to perform the lab as per the following step-by-step instructions.

Both files are stored in a single GitHub repository. You will need to create a free account to download the files.

GitHub Download

Note: Because MCC generates source and header files and libraries under the project folder, the contents of this ZIP file can be placed in any folder of your choice.

Lab Index

Note: Steps 1 - 5 must be completed before you are ready to build, download, and run the application.

Steps

Back to Top