30.1.2.8 Asynchronous Reception Setup

  1. Initialize the SPxBRGH:SPxBRGL register pair and the BRGH and BRG16 bits to achieve the desired baud rate (see EUSART Baud Rate Generator (BRG)).
  2. Set the RXxPPS register to select the RXx/DTx input pin.
  3. Clear the ANSEL bit for the RXx pin (if applicable).
  4. Enable the serial port by setting the SPEN bit. The SYNC bit must be cleared for asynchronous operation.
  5. If interrupts are desired, set the RCxIE bit of the PIEx register and the GIE and PEIE bits of the INTCON register.
  6. If 9-bit reception is desired, set the RX9 bit.
  7. Enable reception by setting the CREN bit.
  8. The RCxIF Interrupt Flag bit will be set when a character is transferred from the RSR to the receive buffer. An interrupt will be generated if the RCxIE interrupt enable bit was also set.
  9. Read the RCxSTA register to get the Error flags and, if 9-bit data reception is enabled, the ninth data bit.
  10. Get the received eight Least Significant data bits from the receive buffer by reading the RCxREG register.
  11. If an overrun occurred, clear the OERR flag by clearing the CREN receiver enable bit.