Low Power Application on SAM D21 Using Harmony v3 Peripheral Libraries: Step 2
Configure Real-Time Clock (RTC) Peripheral Library
Under the bottom left Available Components tab, expand 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 and configure the RTC PLIB to generate a compare interrupt every 500 milliseconds.
Configure I²C Peripheral Library, I²C Pins, and Verify I²C Clock
Under the Available Components tab, expand Peripherals > SERCOM. 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 tab by clicking MHC > Tools > Pin Configuration.
Select the MHC Pin Settings tab and sort the entries by Ports.
Now, 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 Available Components tab, expand Peripherals > SERCOM.
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 the Pin Table tab and then scroll down to the SERCOM3 module as follows.
- Enable USART_TX (SERCOM3_PAD0) on PA22 (Pin #43)
- Enable USART_RX (SERCOM3_PAD1) on PA23 (Pin #44)