Step 3: Configure MCU Resources with MCC

Step 3.1: Launch MCC

Open the MCC plugin by clicking Tools > Embedded > MPLAB Code Configurator v4: 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.

Upon loading for the first time, a window will pop up to save the MCC configuration file. Click Save.


Step 3.2: Configure System Module

Now you can start configuring the settings.


Click System Module in the upper left window.



For System Module, we will use the FRC Oscillator as the Clock Source which is the default configuration. In this example code, we use a faster system clock by enabling the PLL. Enable the PLL by clicking the PLL Enable checkbox.


Click on the Prescaler drop-down menu and select 4:1. Fosc value should be 32 MHz.



Scroll down the System Module and go to the ICD section. Select Communicate on PGEC2 and PGED2 for the Emulator Pin Placement. These are the ICSP pins used in the PKOB on-board debugger/programmer.


Step 3.3 Configure GPIO

GPIO needs to be configured to drive LEDs and read switch values on the demonstration board.


Select Pin Manager: Grid View in the bottom right window. Click each pin with a green lock as either an input or output as shown in the figure below.



In the Pin Module window, at the top right corner, select the Easy Setup tab and configure the selected GPIO as follows.

Note: The Custom Name must match the table below 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
RA8 GPIO LED_01 No Output None
RA9 GPIO LED_02 No Output None
RA10 GPIO OLED_CS No Output None
RA11 GPIO SWITCH_CH No Input Negative Edge
RA12 GPIO SWITCH_DEBUG No Input Negative Edge
RA13 GPIO METER_RST Yes Output None
RA14 GPIO OLED_RST No Output None
RC4 GPIO OLED_DC No Output None

The Pin Module settings should look like the image below:


Step 3.4 Configure UART

Now we will add the peripherals needed for the project and configure the PAC1934 MCC library. The UART will be configured to send information to the MCP2221A Breakout Module and display data on Tera Term.


Add UART1 by opening the UART folder in the Device Resources window and clicking the + icon for UART1 [PIC24/dsPIC33/PIC32MM MCUs by Microchip Technology, Inc.].



In the UART1 configuration window, click the checkbox next to Redirect Printf to UART. This is used to display information to Tera Term.


Step 3.5 Configure Timer2

Timer2 is used to maintain state machine timing.


Add TMR2 by opening the Timer folder in the Device Resources window and clicking the + icon for TMR2.



Update the TMR2 configuration window as follows:

  • Disable the TMR, this is needed for the customer callback in the application
  • Change the Prescaler to 1:64 to increase Timer Period value
  • Change Timer Period value to 200 ms
  • Enable Timer Interrupt

Step 3.6 Configure SPI

SPI is used to transfer information to be displayed on the OLED W Click.


Add SPI1 by opening the SPI folder in the Device Resources windows and clicking the + icon for SPI1 [PIC24/dsPIC33/PIC32MM MCUs by Microchip Technology, Inc.].



Verify Clock Edge is set to “Idle to Active” in the SPI1 configuration window.


Step 3.7 Configure I2C

The I2C peripheral is used to communicate with the PAC1934 Click board. Both measurement data and control signals will be shared between the PIC24FJ256GA705 MCU and the PAC1934 metering IC using this communication channel.


Add I2C2 by opening the I2C folder in the Device Resources and clicking the + icon for I2C2 [PIC24/dsPIC33/PIC32MM MCUs by Microchip Technology, Inc.].



Change the baud rate to 400000 Hz (400 kHz) to match the I2C2 configuration window below.


Step 3.8 Configure Interrupt Priorities

It is necessary to set up the interrupt priorities to ensure concurrent resource requests are resolved in the correct order.


Select the Interrupt Module in the Project Resource window.



Disable I2C Slave Events and change the priority of Timer2 interrupt to 4 to match the example below.


Step 3.9 Configure Peripheral Pins

These assignments ensure the peripherals communicate using the correct pins on the demonstration board.


In the Pin Manager: Grid View window, in the lower right window tab, lock the following Modules to their assigned pins by clicking on the blue unlock symbol to turn it to a green lock:

  • SPI1: SCK1OUT to RC6
  • SPI1: SDI1 to RB9
  • SPI1: SDO1 to RC2
  • UART1: U1RX to RB8
  • UART1: U1TX to RB7

Once complete, the Pin Manager: Grid View window will look like this:



Click Pin Module in the Project Resources window to check for consistency, refer to the image below.

Note: Click the Function Column to sort the list according to Function for easier verification.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.