Migrating ASF SAM C21 Application to MPLAB® Harmony v3 PIC32CM MC: Step 2
Procedure
Configure I²C Peripheral Library and I²C Pins
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.
- The SERCOM2 (as I²C) retains the default 100 kHz speed because the temperature sensor chip on the I/O1 Xplained Pro Extension Kit can operate at 100 kHz I²C speed.
- The SERCOM2 (as I²C) retains the default 50-100 nanoseconds hold time for Serial Data (SDA) Hold Time because it aligns with the minimum (50 nanoseconds) start hold time in the specification of the temperature sensor chip (AT30TSE758).
- The SERCOM2 (as I²C) retains the default 100 nanoseconds for I2C Trise time because it aligns with the maximum (300 nanoseconds) input rise time in the specification of the temperature sensor chip (AT30TSE758).
Open the Pin Configuration tab by clicking MHC > Tools > Pin Configuration.
Select the MPLAB® Harmony Configurator (MHC) Pin Settings tab and sort the entries by Ports.
Now, select the MHC Pin Table tab and then scroll down to the SERCOM2 module as follows.
Enable I²C Clock (I2C_SCK)(SERCOM2_PAD1) on Pin #22 (PA13)
- Enable I²C Data (I2C_SDA)(SERCOM2_PAD0) on Pin #21 (PA12)
This completes the configuration of the I²C peripheral library. The application code will use the I²C PLIB Application Programming Interfaces (APIs) to read the temperature from the temperature sensor.
Configure Universal Synchronous Asynchronous Receiver Transmitter (USART) Peripheral Library, USART Pins, and link STDIO Library
Under the tab Available Components tab, expand Peripherals > SERCOM.
Double-click on SERCOM0 to add the SERCOM instance 0 to the project.
Associate STDIO tool with SERCOM instance 0 (USART) peripheral by right-clicking on the yellow diamond.
Select the SERCOM0 Peripheral Library in the Project Graph, verify default SERCOM Operation Mode configuration is set as USART and configure it.
Select the Pin Table tab and then scroll down to the SERCOM0 module as follows.
Enable USART_TX (SERCOM0_PAD2) on Pin #11 (PA06)
- Enable USART_RX (SERCOM0_PAD3) on Pin #12 (PA07)