2.3.3 How to Configure the Pins
Since only the transmission is necessary for this use case, only the TX pin must be configured. The pin used as TX in this example, is the RD0 pin and it must be configured using the Peripheral Pin Select (PPS). To find the value that needs to be written to the RD0PPS register, inspect the Peripheral PPS Output Selection Codes table below, taken from the device data sheet.
RxyPPS | Pin Rxy Output Source | PORT to Which Output can be Directed | |||||||
---|---|---|---|---|---|---|---|---|---|
28-Pin Devices | 40-Pin Devices | ||||||||
0x0C | EUSART2 (DT) | — | B | C | — | B | — | D | — |
0x0B | EUSART2 (TX/CK) | — | B | C | — | B | — | D | — |
0x0A | EUSART1 (DT) | — | B | C | — | B | C | — | — |
0x09 | EUSART1 (TX/CK) | — | B | C | — | B | C | — | — |
The following line will route the EUSART2 TX to RD0:
/* RD0 is TX2 */
RD0PPS = 0x0B;
The pin direction is set by default as output, but if it were not, the following line sets it.
/* Configure RD0 as output. */
TRISDbits.TRISD0 = 0;
Function | Pin |
---|---|
EUSART2 TX | RD0 |
Before sending data, the user needs to check if the previous transmission is complete by checking the PIR3.TXnIF bit field. The following code example waits until the transmit buffer is empty, then writes a character to the TXnREG register:
static void EUSART2_write(uint8_t txData)
{
while(0 == PIR3bits.TX2IF)
{
;
}
TX2REG = txData;
}
Use MPLAB X Data Visualizer as described in the appendix, How to Receive Data in MPLAB X Data Visualizer.