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