BYTE USART5_RxBuf[USART5_RX_BUFFER_SIZE];
BYTE USART5_RxTail;
BYTE USART5_RxHead;
The interrupt priority and sub-priority bit masks can
be found in the interrupts section of the
PIC32MX575F512H datasheet. If you like your turnip
greens from a can, you can also get these definitions in a
more descriptive form from the PIC32MX575F512H
include file that is part of the Microchip XC32 C compiler.
The rest of the USARTs are initialized in this manner:
The FTDI USB-to-serial IC utilizes USART1. USART2 is
dedicated to the Atmel ATmega328P that handles the
microSD drive. USART4 is electrically connected to the
ST3232 RS-232 driver/receiver. The ACKme Wi-Fi module
communicates with the PIC32MX575F512H on the
//Initialize UART1 FTDI
U1BRG = 43; // Set Baud rate 115200 bps
U1STA = 0;
U1MODE = 0x00008000;
// Enable UART for 8-none-1
U1STASET = 0x00001400;
// Enable Transmit and Receive
//priority 2 sub priority 3 - 00011111 bits
//<4:2> sub bits <0:1>
IPC6SET = 0x0000000B;
IEC0SET = 0x08000000;
IFS0CLR = 0x08000000;
// flush receive buffer
USART1_RxTail = 0x00;
USART1_RxHead = 0x00;
//Initialize UART2 ATMega328P - microSD
U2BRG = 520; // Set Baud rate 9600
U2STA = 0;
U2MODE = 0x00008000;
// Enable UART for 8-none-1
U2STASET = 0x00001400;
// Enable Transmit and Receive
//priority 2 sub priority 3 - 00011111 bits
//<4:2> sub bits <0:1>
IPC8SET = 0x0000000B;
IEC1SET = 0x00000200;
IFS1CLR = 0x00000200;
// flush receive buffer
USART2_RxTail = 0x00;
USART2_RxHead = 0x00;
USART5 interface.
USART Setups
Once the USART data memory is allocated, we can
power up each USART module and define their associated
interrupt mechanisms. The USARTs all have some
common settings such as data length, parity, and the
number of stop bits. However, enabling the individual
interrupt engines is slightly different for each USART. As
you would imagine, the USART initialization takes place in
the hardware initialization function. Here’s how we set up
USART1:
//Initialize UART4 RS-232
U4BRG = 520; // Set Baud rate 9600
U4STA = 0;
U4MODE = 0x00008000;
// Enable UART for 8-none-1
U4STASET = 0x00001400;
// Enable Transmit and Receive
//priority 2 sub priority 3 - 00011111 bits
//<12:10> sub bits <9:8>
IPC12SET = 0x00000B00;
IEC2SET = 0x00000010;
IFS2CLR = 0x00000010;
//flush receive buffer
USART4_RxTail = 0x00;
USART4_RxHead = 0x00;
//Initialize UART5 WiFi
U5BRG = 43; // Set Baud rate 115200
U5STA = 0;
U5MODESET = 0x00008000;
// disable UART for 8-none-1
September 2015 71