Using the HC12 Serial Communications Interface
- Set baud rate with SBR12-0 of SC0BDH and SC0BDL
For example, for 9600 baud:
- Enable transmitter and receiver (TE and RE bits of
SC0CR2)
- Select 8-bit or 9-bit mode (M bit of SC0CR1)
- If using parity, enable parity (PE bit of SC0CR1) and
choose odd or even (PT bit of SC0CR1)
- If using interrupts enable TIE or RIE interrupt
in SC0CR2
To transmit data:
- If sending 9 bit data, write T8 bit to SC0DRH
- Write data to SC0DRL
- Wait for transmit data register empty TDRE bit of SC0SR1, or
transmit interrupt if enabled.
- Send next data word.
To receive data:
- Wait for receive data register full RDRF bit of SC0CR1, or
for receive interrupt
- Read data from SC0DRL (if receiving 9-bit data, get ninth bit from
R8 bit of SC0DRH)
- If desired check for overrun error, noise flag, framing error, or parity
error.
If both receive and transmit interrupts enabled need to check in interrupt
service routine to see if transmit interrupt or receive interrupt is active.
Bill Rison
Wed Apr 14 17:26:06 MDT 1999