MPLAB® Harmony v3 Peripheral Libraries on SAM D21: Step 2
Configure I²C, USART and RTC Peripheral Libraries
Configure Real-Time Clock (RTC) Peripheral Library
In the clock manager, set the RTC to run at a 1000 Hz low-speed clock.
When a module is added to the project graph, MHC automatically enables the clock to the module. The default RTC clock source is a 48 MHz Generic Clock Generator 0 (GCLK0).
Go back to the project graph and configure the RTC PLIB to generate a compare interrupt every 500 milliseconds.
Configure I²C PLIB and I²C Pins
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 as shown in the accompanying image.
Open the Pin Configuration tabs by clicking Tools > Pin Configuration.
Select the MHC Pin Settings tab and sort the entries by Ports, as shown in the accompanying image.
Now, select the MHC Pin Table tab and then scroll down to the SERCOM2 module as shown in the accompanying image.
- Enable I²C Clock (TWI_SCL)(SERCOM2_PAD1) on PA09 (Pin #18)
- Enable I²C Data (TWI_SDA)(SERCOM2_PAD0) on PA08 (Pin #17)
Configure Universal Synchronous Asynchronous Receiver Transmitter (USART) PLIB and USART Pins
Double-click on SERCOM3 to add the SERCOM instance 3 to the project.
Select the SERCOM3 Peripheral Library in the project graph. Verify that the default SERCOM Operation Mode configuration is set as USART and configure it as shown in the accompanying image.
Verify that the default baud rate is set to 115200 Hz.
Enable USART_TX on PA22 (Pin #43).
Configure DMA PLIB
Open the DMA Configurator tab by clicking Tools > DMA Configuration.
In the DMA Settings window, configure DMA Channel 0 to transfer the application buffer to the USART TX register. The DMA transfers one byte from the user buffer to USART transmit buffer on each trigger.
Based on the trigger source, the DMA channel configuration is automatically set by MHC.
- Trigger Action: Action taken by DMA on receiving a trigger.
- One beat transfer: Generally used during a memory-to-peripheral or peripheral-to-memory transfer.
- One block transfer: Generally used during the memory-to-memory transfer on a software trigger.
- Source Address mode, Destination Address mode: Select whether to increment the Source/Destination Address after every transfer. Automatically set by MHC based on the trigger type. For example:
- If the trigger source is USART transmit, then the Source Address is incremented, and the Destination Address is fixed.
- If the trigger source is USART receive, then the Source Address is fixed, and the Destination Address is incremented.
- Beat Size: Size of one beat. The default value is 8 bits. For example:
- If the Serial Peripheral Interface (SPI) peripheral is configured for 16-bit/32-bit mode, then the beat size must be set to 16-bits/32-bits respectively.
Click on Add Channel to add the DMA channel and configure the DMA channel as shown in the accompanying image.