Demonstrating Secure Digital Flash Memory Card Functionality Using MPLAB® Code Configurator (MCC)
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.
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.
Reference Materials
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
Connection Diagram
The application has the Mikroe microSD Click board connected to GPIO and SPI1 and MCP2221A breakout module connected to UART1.
Software Tools
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.
Lab Index
Steps
- Step 1: Connect Hardware
- Step 1.1 - Attach microSD Click board
- Step 1.2 - Connect USB from PIC24FJ256GA7 Curiosity board to computer
- Step 1.3 - Connect USB from MCP2221A Breakout Module to computer
- Step 2: Download Example Code and Set Up MCC
- Step 2.1 - Download and Extract Example Code
- Step 2.2 - Install MPLAB Code Configurator (MCC)
- Step 2.3 - Install MCC File System Library
- Step 3: Configure MCU Resources With MCC
- Step 3.1 - Launch MCC
- Step 3.2 - Add File System and SD/MMC Card MCC Libraries
- Step 3.3 - System Module
- Step 3.4 - UART
- Step 3.5 - GPIO
- Step 4: Configure File System and SD/MMC Card Libraries
- Step 4.1 - Configure File System Library and Add SD/MMC Card Library
- Step 4.2 - Configure SD/MMC Card Library
- Step 5: Build and Program
- Step 5.1 - Build project
- Step 5.2 - Program MCU
- Step 6: Test Application
- Step 6.1 - Open, configure Data Visualizer
- Step 6.2 - Select displayed parameters
- Step 6.3 - Verify correct operation
- Step 6.4 - Results
- Step 6.5 - Analysis
- Step 6.6 – Conclusions