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.

Picture10.jpg

Or, you may click the MCC logo in the toolbar.

MCCicon.png

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.

Picture12.jpg

Step 3.2: Configure System Module

Now you can start configuring the settings.

1

Click System Module in the upper left window.

SystemModule.png

2

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.

3

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

Picture13.jpg

4

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.

Picture14.jpg

Step 3.3 Configure GPIO

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

1

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.

Picture15.jpg

2

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
RC8 GPIO METER_SLOW Yes Output None

The Pin Module settings should look like the image below:

PinModule.png

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.

1

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.].

Picture17.jpg

2

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

Picture18.jpg

Step 3.5 Configure Timer2

Timer2 is used to maintain state machine timing.

1

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

Picture19.jpg

2

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
Picture20.jpg

Step 3.6 Configure SPI

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

1

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.].

Picture21.jpg

2

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

Picture22.jpg

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.

1

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.].

Picture23.jpg

2

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

Picture24.jpg

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.

1

Select the Interrupt Module in the Project Resource window.

InterruptModule.png

2

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

Picture25.jpg

Step 3.9 Configure Peripheral Pins

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

1

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:

Picture26.jpg

2

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.

Picture28.jpg
© 2022 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.