34.6.4.2.1 Initialization

The following registers are enable-protected, meaning that they can only be written when the SPI is disabled (CTRLA.ENABLE=0):

  • Control A register (CTRLA), except Enable (CTRLA.ENABLE) and Software Reset (CTRLA.SWRST)
  • Control B register (CTRLB)
  • Baud register (BAUD)
  • Address register (ADDR)

When the SPI is enabled or is being enabled (CTRLA.ENABLE=1), any writing to these registers will be discarded

When the SPI 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.

Initialize the SPI by following these steps:

  1. Select SPI mode in host/client operation in the Operating Mode bit group in the CTRLD register (CTRLD.MODE= 0x2 or 0x3 ).
  2. Select Transfer mode for the Clock Polarity bit and the Clock Phase bit in the CTRLD register (CTRLD.CPOL and CTRLD.CPHA) if desired.
  3. Select the Frame Format value in the CTRLD register (CTRLD.FORM).
  4. Configure the Data In Pinout field in the Control D register (CTRLD.DIPO) for SERCOM pads of the receiver.
  5. Configure the Data Out Pinout bit group in the Control D register (CTRLD.DOPO) for SERCOM pads of the transmitter.
  6. Select the Character Size value in the CTRLB register (CTRLB.CHSIZE).
  7. Write the Data Order bit in the CTRLD register (CTRLD.DORD) for data direction.
  8. If the SPI is used in Host mode:
    • Select the desired baud rate by writing to the Baud register (BAUD).
    • If Hardware SS control is required, write '1' to the Host Client Select Enable bit in CTRLB register (CTRLB.MSSEN).
  9. Enable the receiver by writing the Receiver Enable bit in the CTRLE register (CTRLE.RXEN=1).