It is necessary to follow some steps inorder to implement asynchronous transmission on PIC microcontrollers. And these steps are summarized below:
- Initialize the SPBRG register for the appropriate baud rate. In the case high speed baud rate is rquired, set bit BRGH.
- Dont forget to enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
- For interrupt based transmission enable bit TXIE.
- For 9-bit transmission is desired, then set transmit bit TX9.
- Enable the transmission by setting bit TXEN, which will also set bit TXIF.
- If 9-bit transmission is selected, the ninth bit should be loaded in bit TX9D.
- Load data to the TXREG register (starts transmission). It is to be noted, transmission starts immediately after TXREG is loaded.
- If using interrupts, ensure that GIE bit and PEIE bit (bits 7 and 6 of the INTCON register) are set.