MPLAB® Harmony v3 Peripheral Libraries on SAM E70/S70/V70/V71: Step 2
Configure TC Peripheral Library
Under the bottom left Available Components tab, expand Peripherals > TC.
Double-click or drag and drop TC0 to add the Timer Clock 0 (TC0) Peripheral Library (PLIB) to the project graph.
Set the TC0 to run at 1000 Hz low-speed clock.
When a module is added to the project graph, MPLAB® Harmony Configurator (MHC) automatically enables the clock to the module. The default TC0 clock source is 32000 Hz Slow Clock (SLCK).
Go back to the project graph and configure the TC0 PLIB to generate a compare interrupt every 500 milliseconds.
Configure I²C Peripheral Library and I²C pins
Under the Available Components tab, expand Peripherals > TWIHS
Double-click on Two-Wire Interfaces 0 (TWIHS0) to add the TWIHS instance 0 to the project.
Select the TWIHS 0 PLIB and configure it for I²C protocol as shown.
Open the Pin Configuration tabs by clicking MHC > Tools > Pin Configuration.
Select the MHC Pin Settings tab and sort the entries by Ports names as shown below.
Now, select the MHC Pin Table tab and then scroll down to the TWIHS0 module as shown below.
- Enable I²C Clock (TWIHS0_TWCK0) on PA04 (Pin #77)
- Enable I²C Data (TWIHS0_TWD0) on PA03 (Pin #91)
This completes the configuration of the I²C PLIB. The application code will use the I²C PLIB Application Programming Interfaces (APIs) to read the temperature from the temperature sensor.
Configure USART Peripheral Library and USART pins
Under the tab Available Components tab, expand Peripheral > USART.
Double-click on USART1 to add the Universal Synchronous Asynchronous Receiver Transmitter (USART) instance 1 to the project.
Select the USART1 PLIB in the Project Graph and configure it for USART protocol, including setting the baud rate to 115200Hz.
Select the Pin Table tab and then scroll down to the USART1 module as shown below.
Enable USART_TX on PB04 (Pin #105).
Configure DMA Peripheral Library
Launch DMA Configurator by going to the MHC tab in MPLAB X IDE and then select Tools > DMA Configuration.
Click on the DMA Settings tab. Configure Direct Memory Access (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.
- Source Address Mode, Destination Address Mode: Select whether to increment 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.
- Data Width: Size of one transfer. The default value is 8-bits. For example:
- If the Serial Peripheral Interface (SPI) is configured for 16-bit/32-bit mode, then the data width must be set to 16-bits/32-bits respectively.
- Chunk Size: Some peripherals can hold more than one data as they have an internal FIFO. To optimize the data transfer, the chunk size can be set to match the internal FIFO size of the peripheral FIFO.
- In the default configuration, the chunk size is set to 1 request (1 byte) per transfer.
- Memory Burst Size: This is a very fast data transfer mode. It can perform up to 16 transfers (beats) before releasing the control of the system bus back to the CPU. The default value of burst length is one transfer.
- In the default configuration, USART is configured for one-byte data at a time. So, the burst length is configured as one transfer.
Disable USART interrupt
- Under the Project Graph tab, click on the USART1 block.
- In the Configuration Options, uncheck the Enable Interrupts option.