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 (SPIn.CTRLA).
  3. 3.In Master mode, select the clock speed by writing the Prescaler bits (PRESC) and the Clock Double bit (CLK2X) in SPIn.CTRLA.
  4. 4.Optional: Select the Data Transfer mode by writing to the MODE bits in the Control B register (SPIn.CTRLB).
  5. 5.Optional: Write the Data Order bit (DORD) in SPIn.CTRLA.
  6. 6.Optional: Setup Buffer mode by writing BUFEN and BUFWR bits in the Control B register (SPIn.CTRLB).
  7. 7.Optional: To disable the multi-master support in Master mode, write ‘1’ to the Slave Select Disable bit (SSD) in SPIn.CTRLB.
  8. 8.Enable the SPI by writing a ‘1’ to the ENABLE bit in SPIn.CTRLA.