Low-Power Application on SAM D21 Using MPLAB® Harmony v3 Peripheral Libraries: Step 2
Configure Real-Time Clock (RTC) Peripheral Library
Under the bottom left Device Resources tab, expand Harmony > Peripherals > RTC.
Double-click or drag and drop RTC to add the RTC Peripheral Library (PLIB) to the project graph.
In the Clock Easy View, open the Peripheral Clock Configuration window by clicking on the Peripheral Clock Configuration button.
Once the window is opened, scroll down to the RTC peripheral and select GCLK1 (1 kHz) as the source clock to generate the peripheral clock frequency.
Go back to the Project Graph, select the RTC module, and in Configuration Options, configure the RTC PLIB to generate a compare interrupt every 500 milliseconds.
Configure Inter-Integrated Circuit (I²C) Peripheral Library, I²C Pins, and Verify I²C Clock
Under the Device Resources tab, expand Harmony > Peripherals > SERCOM.
Expand SERCOM and double-click on SERCOM2 to add the SERCOM instance 2 to the project.
Select the SERCOM 2 Peripheral Library and configure it for the I²C protocol.
Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration.
Select the Pin Settings tab and sort the entries by Ports, as shown in Figure 8.
Now, In the Pin Settings tab scroll down to the PA08 and PA09 pins as follows.
- Enable I²C Clock (TWI_SCL)(SERCOM2_PAD1) on PA09 (Pin #18)
- Enable I²C Data (TWI_SDA)(SERCOM2_PAD0) on PA08 (Pin #17)
In Clock Easy View, open the Peripheral Clock Configuration by clicking on the button Peripheral Clock Configuration.
Once the window is opened, scroll down to the SERCOM2_CORE peripheral and verify GCLK0 (48 MHz) as the source clock to generate the peripheral clock frequency.
Configure Universal Synchronous Asynchronous Receiver Transmitter (USART) Peripheral Library, USART Pins, and Verify USART Clock
Under the Device Resources tab, expand Harmony > Peripherals > SERCOM.
Expand SERCOM and double-click on SERCOM3 to add the SERCOM instance 3 to the project.
Associate the STDIO tool with SERCOM instance 3 (USART) peripheral by right-clicking on the yellow diamond.
In Clock Easy View, open the Peripheral Clock Configuration by clicking on the Peripheral Clock Configuration button.
Once the window is opened, scroll down to the SERCOM3_CORE peripheral and set GCLK2 (32 kHz) as the source clock to generate the peripheral clock frequency.
Select the SERCOM3 Peripheral Library in the Project Graph, verify the default SERCOM Operation Mode configuration is set as USART, and configure it.
The default Baud rate is set to 4800 Hz, as the peripheral is set at a low-frequency clock of 32 kHz.
Select Pin Settings tab and scroll down to the PA22 and PA23 pins as follows.
- Enable USART_TX (SERCOM3_PAD0) on PA22 (Pin #43)
- Enable USART_RX (SERCOM3_PAD1) on PA23 (Pin #44)