MPLAB® Code Configurator (MCC) is a free graphical programming environment that generates seamless, easy-to-understand C code to insert into your project. Using an intuitive interface, it enables and configures a rich set of peripherals and functions specific to your application. It supports our 8-, 16- and 32-bit devices, which include our PIC®, AVR®, SAM microcontrollers (MCUs), and dsPIC® Digital Signal Controllers (DSCs). Both the downloadable MPLAB X Integrated Development Environment (IDE) and the cloud-based MPLAB Xpress IDE include MCC.
We’ll use MCC to configure the needed MCU peripherals and general-purpose inputs and outputs (GPIO) to complete the exercise.
Step 3.1 - Launch MCC
1
Open MPLAB X IDE and open the downloaded project microSD-app-pic24fjxxxga7-lab.X.
2
Launch the MCC plugin by clicking Tools > Embedded > MPLAB Code Configurator v5: Open/Close.
Or, you may click the MCC logo in the toolbar.
Use the same method to close MCC.
Note: MCC may take a while to load the first time it is launched.
Step 3.2 – Add File System and SD/MMC Card MCC Libraries
Note: The File System MCC and SD/MMC Card libraries provide an easy-to-use graphical interface to configure the various options of the microSD Click board™.
Note: This process shows how to add the required MCC libraries to a new MPLAB X IDE project. At the time of this publication, MCC requires additional steps to add some libraries. Please refer to this article if you have trouble adding MCC libraries to an existing MPLAB X IDE project.
1
If prompted, select MCC Classic from MCC Content Manager Wizard.
2
Select FatFs FAT System and SD/MMC Card libraries and click Finish.
3
After MCC loads, the FatFs and SD Card (SPI) libraries may be available in the Device Resources window. If so, add the FatFs and SD Card (SPI) libraries by clicking on their + symbols.
The libraries will now be listed in the Project Resources window.
Step 3.3 – Configure System Module
Now you can start configuring the settings.
1
Click System Module in the upper left window.
2
For System Module, we will use the FRC Oscillator as the Clock Source, which is the default configuration. In this exercise, we will use an 8 MHz Fosc clock source.
3
Scroll down the System Module and go to the ICD section. Verify that Communicate on PGEC2 and PGED2 is selected for the Emulator Pin Placement. These are the ICSP pins for the PICKit™ on-board debugger/programmer.
Step 3.4 – Configure UART
Now we will add the peripherals needed for the project and configure the File System Library. The UART will be configured to send information to the MCP2221A Breakout Module and display data on MPLAB X IDE’s Data Visualizer.
1
Add UART1 by opening the UART folder in the Device Resources window and clicking the + icon for UART1 [Foundation Services Library by Microchip Technology, Inc.].
2
In the UART1 configuration window, click the checkbox next to Redirect Printf to UART. This is used to display information to Data Visualizer.
Step 3.5 – Configure GPIO
GPIO needs to be configured to control the microSD Click board.
1
Select Pin Module in Project Resources. Find the Pin Manager: Grid View window. Click each pin with a green lock as either an input or output as shown in the following figure.
- SD Card (SPI) CD – Port C1
- SD Card (SPI) CS – Port C9
- SPI1 SCK1OUT – Port B15
- SPI1 SDI1 – Port B13
- SPI1 SDO1 – Port B14
- UART1 U1RX – Port B8
- UART1 U1TX – Port B7
In the Pin Module window, select the Easy Setup tab and configure the selected GPIO as follows:
Note: The Custom Name must match the following table for the libraries to build successfully. You may copy the Custom Name from the table below and paste it into the Pin Module Custom Name fields.
Pin Name | Function | Custom Name | Start High | Direction | Interrupt-on-change |
---|---|---|---|---|---|
RB7 | U1TX | Yes | Output | None | |
RB8 | U1RX | No | Input | None | |
RB13 | SDI1 | SDI1 | No | Input | None |
RB14 | SDO1 | SDO1 | No | Output | None |
RB15 | SCK1OUT | SCK1OUT | No | Output | None |
RC1 | CD | SDCard_CD | No | Input | None |
RC9 | CS | SDCard_CS | No | Output | None |
The Pin Module settings should look like the following image: