(XC16) How do I instruct the compiler to divert the output of printf to UART2?
In the XC16 compiler, the __C30_UART compiler-defined variable is available. It decides the UART channel to use for printing the output of printf(). This is defined in the file c30_uart.c, available under the compiler installation (<Compiler-DIR>\src\libpic30\pic30). The __C30_UART variable decides whether the output is directed to UART1 or UART2. By default, __C30_UART is 1. So, the output of printf() will be directed via UART1. To divert the output from UART1 to UART2, you need to change the __C30_UART value to 2 before invoking the printf() routine.
Example
This program will transmit the “Hello world” string through UART2.