Step 2.1: Configure TC Peripheral Library
2
Set the TC0 to run at 1000 Hz low-speed clock.
When a module is added to the project graph, MPLAB® Code Configurator (MCC) automatically enables the clock to the module. The default TC0 clock source is 32000 Hz Slow Clock (SLCK).
On the SAME70 device, TC0 can be clocked from various clock sources with frequencies ranging from 32 kHz to 300 MHz as shown above. TC0 can be sourced through a low-speed clock using the clock divisor. In the above screenshot, TC0 is sourced through a 1000 Hz low-speed clock source. The 1000 Hz low-speed clock is enough to generate periods at 500 milliseconds, 1 second, 2 seconds, and 4 seconds.
Step 2.2: Configure I²C Peripheral Library and I²C pins
1
Under the Device Resources tab, expand Harmony > 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.
The TWIHS0 (I²C) retains the default 400 kHz speed because the temperature sensor chip on I/O1 Xplained Pro Extension Kit can operate at 400 kHz I²C speed.
3
Select the Plugins > Pin Settings tab and sort the entries by Ports names as shown below.
Now, select the 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.
Step 2.3: Configure USART Peripheral Library and USART pins
1
Under the tab Device Resources tab, expand Harmony > 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.
2
Select the Pin Table tab and then scroll down to the USART1 module as shown below.
Enable USART_TX on PB04 (Pin #105).
The application will use the USART PLIB for printing messages on the serial terminal. Hence, in the USART1 configuration, only the transmit functionality is enabled and the receive functionality is disabled.
Step 2.4: Configure DMA Peripheral Library
2
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 MCC.
- Source Address Mode, Destination Address Mode: Select whether to increment Source/Destination Address after every transfer. Automatically set by MCC 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.