30.1.2.8 Asynchronous Reception Setup
- Initialize the SPxBRGH:SPxBRGL register pair and the BRGH and BRG16 bits to achieve the desired baud rate (see EUSART Baud Rate Generator (BRG)).
- Set the RXxPPS register to select the RXx/DTx input pin.
- Clear the ANSEL bit for the RXx pin (if applicable).
- Enable the serial port by setting the SPEN bit. The SYNC bit must be clear for asynchronous operation.
- If interrupts are desired, set the RCxIE bit of the PIEx register and the GIE and PEIE bits of the INTCON register.
- If 9-bit reception is desired, set the RX9 bit.
- Enable reception by setting the CREN bit.
- 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.
- Read the RCxSTA register to get the error flags and, if 9-bit data reception is enabled, the ninth data bit.
- Get the received eight Least Significant data bits from the receive buffer by reading the RCxREG register.
- If an overrun occurred, clear the OERR flag by clearing the CREN receiver enable bit.