(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.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.