Initialization

Initialize the SPI to a basic functional state by following these steps:
  1. 1.Configure the SS pin in the Port peripheral.
  2. 2.Select SPI Master / Slave operation by writing the Master/Slave Select bit (MASTER) in the Control A register (SPI.CTRLA).
  3. 3.In Master mode, select the clock speed by writing the Prescaler bits (PRESC) and the Clock Double bit (CLK2X) in SPI.CTRLA.
  4. 4.Optional: Select the data transfer mode by writing to the MODE bits in the Control B register (SPI.CTRLB).
  5. 5.Optional: Write the Data Order bit (DORD) in SPI.CTRLA.
  6. 6.Optional: Setup buffer mode by writing BUFEN and BUFWR bits in the Control B register (SPI.CTRLB).
  7. 7.Optional: To disable the multimaster support in Master mode, write '1' to the Slave Select Disable bit (SSD) in SPI.CTRLB.
  8. 8.Enable the SPI by writing a '1' to the ENABLE bit in SPI.CTRLA.