Using the HC12 Serial Peripheral Interface

Things to set up when using the HC12 SPI subsystem

Use the following registers:


  1. Enable SPI (SPE bit of SP0CR1)
  2. Clock phase and polarity set to match device communicating with
  3. Select clock polarity - CPOL bit of SP0CR1
  4. Select clock phase - CPHA bit of SP0CR1
  5. Select master or slave MSTR bit of SP0CR1
  6. If you want to receive interrupt after one byte transfered, enable interrupts with SPIE bit of SP0CR1
  7. Configure LSBF of SP0CR1 for MSB first (LSBF = 0) or LSB first (LSBF = 1)
  8. Configure for normal mode by clearing bit SPC0 of SP0CR2

Master Mode:

  1. Set clock rate - SPR2:0 bits of SP0BR
  2. Make MOSI, SCLK, and SS output - bits DDS5, DDS6, DDS7 of DDRS
  3. MISO automatically configured as input by choosing master mode
  4. Configure some way to select slave(s) - probably SS if only one slave; other I/O bits if multiple slaves
  5. Start data transfer by writing byte to SP0DR
  6. After transfer complete (8 clock cycles), SPIF bit of SP0SR set.
  7. Set up SSOE of SP0CR1

Slave Mode:

  1. No need to set clock mode - slave accepts data at rate sent by master (up to 4 MHz)
  2. Need to make MISO output - bit DDS4 of DDRS
  3. No need to Make MOSI, SCLK, and SS inputs - this is done automatically when configuring HC12 as slave

Bill Rison