(XC16) How Do I instruct the compiler to divert the output of printf to UART2?
In the XC16 compiler, a compiler defined variable ‘__C30_UART’ is available, which 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’ decides whether output is directed to UART1 or UART2. By default, __C30_UART is 1. So output of printf() will be directed via UART1. To divert the output from UART1 to UART2, you need to change __C30_UART value to 2 before invoking the printf() routine.
Example:
This program will transmit the “Hello world” string through UART2.