2 UART Transmit
The following steps outline the transmission process:
- Configure the UxBRGH:UxBRGL register pair and BRGS bit to achieve the desired baud rate.
- Set the MODE<3:0> bits of UxCON0 to the desired operation mode.
- Set the TXPOL bit of UxCON2 if an inverted TX output is desired.
- Load the RxyPPS register with the code associated with the TX output.
- Clear the TRIS bit for the TX pin.
- If UART interrupts are desired, set the appropriate interrupt enable bits, clear the associated interrupt flag bits, and enable the global interrupts.
- Enable the UART module by setting the ON bit of UxCON1.
- Set the TXEN bit of UxCON0 to enable the transmitter.
- Check the UxTXIF bit to ensure the UxTXB is clear before writing.
- When ready to begin transmission, write one byte of data to UxTXB.
- Repeat steps 9 and 10 until all the data has been transmitted.
UART Transmit Mode Initialization for PIC18(L)FXXK42 shows the UART initialization sequence when operating in Transmit mode.
UART Transmit Mode Initialization for PIC18(L)FXXK42
void UART1_Initialize(void)
{
U1CON0 = 0x80; // BRGS normal; 8-bit mode; ABDEN disabled;
U1CON1 = 0x80; // ON enabled;
U1CON2 = 0x00; // TXPOL not inverted; FLO off;
U1BRGL = 0x19; // BRGL 25 = 9600 BR @ 1 MHz FOSC
U1BRGH = 0x00;
U1FIFO = 0x00; // STPMD in middle of first Stop bit;
U1UIR = 0x00; // Auto-baud not enabled
U1ERRIR = 0x00;
U1ERRIE = 0x00;
U1CON0bits.TXEN = 1; // Enable the transmitter
}