32.6.2.1 Initialization
The SERCOM bus clock (CLK_SERCOMx_APB) is required to access the SERCOM registers. This clock must be enabled in the MCLK - Main Clock Controller.
Two generic clocks are used by the SERCOM in I2C mode: GCLK_SERCOMx_CORE can clock the I2C when working as a Host, and GCLK_SERCOM_SLOW is required only for certain functions, for example, SMBus timing. These two clocks must be configured and enabled in the GCLK - Generic Clock Controller before using the I2C.
- The Control A register (CTRLA), except the Enable (CTRLA.ENABLE) and Software Reset (CTRLA.SWRST) bits
- The Control B register (CTRLB), except the Acknowledge Action (CTRLB.ACKACT) and Command (CTRLB.CMD) bits
- The Baud register (BAUD)
- The Address register (ADDR) in Client operation.
When the I2C is enabled or is being enabled (CTRLA.ENABLE = 1), writing to these registers will be discarded. If the I2C is being disabled, writing to these registers will be completed after the disabling.
Enable-protection is denoted by the "Enable-Protection" property in the register description.
- Select I2C Host or Client mode by writing 0x4 (Client mode) or 0x5 (Host mode) to the Operating Mode bits in the CTRLA register (CTRLA.MODE).
- If required, select the SDA Hold Time value in the CTRLA register (CTRLA.SDAHOLD).
- If required, enable smart operation by setting the Smart Mode Enable bit in the CTRLB register (CTRLB.SMEN).
- If required, enable SCL low time-out by setting the SCL Low Time-Out bit in the Control A register (CTRLA.LOWTOUTEN).
- In Host mode:
- Select the inactive bus time-out in the Inactive Time-Out bit group in the CTRLA register (CTRLA.INACTOUT).
- Write the Baud Rate register (BAUD) to generate the desired baud rate.
- Configure the address match configuration by writing the Address Mode value in the CTRLB register (CTRLB.AMODE).
- Set the Address and Address Mask value in the Address register (ADDR.ADDR and ADDR.ADDRMASK) according to the address configuration.