Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "maindefs.h"
#include "msg_queues.h"
#include <usart.h>
#include "uart.h"
#include "xbee.h"
static UART_DATA *uart_data_ptr;
void uart_init(UART_DATA *ud) {
// Configure the hardware USART device
// UART1 TX RC6
// UART1 RX RC7
Open1USART(USART_TX_INT_OFF & // Interrupt on TX off
USART_RX_INT_OFF & // Interrupt on RX on
USART_ASYNCH_MODE & // Operate in async mode
USART_EIGHT_BIT & // Operate in 8-bit mode
USART_CONT_RX & // Continuously recieve messages
USART_BRGH_HIGH, 25); // Set UART speed to 115200 baud
// UART2 RX Pin RP6
RPINR16 = 10; // 10 is PPS RP10
// UART2 TX Pin RP9
RPOR9 = 6; // 6 is TX2/CK2 (EUSART2 Asynchronous Transmit/Asynchronous Clock Output)
Open2USART(USART_TX_INT_OFF & // Interrupt on TX off
USART_RX_INT_ON & // Interrupt on RX on
USART_ASYNCH_MODE & // Operate in async mode
USART_EIGHT_BIT & // Operate in 8-bit mode
USART_CONT_RX & // Continuously recieve messages
USART_BRGH_HIGH, 25); // Set UART speed to 115200 baud
// // Create the buffer that holds UART messages
// uart_data_ptr = ud;
// uart_data_ptr->buflen = 0;
}
void uart_recv_interrupt_handler() {
if (DataRdy2USART()) {
xbee_read_serial(Read2USART());
}
if (USART2_Status.OVERRUN_ERROR == 1) {
// We've overrun the USART and must reset
RCSTA1bits.CREN = 0;
RCSTA1bits.CREN = 1;
RCSTA2bits.CREN = 0;
RCSTA2bits.CREN = 1;
MQ_sendmsg_ToMainFromHigh(0, MSGTYPE_OVERRUN, (void *) 0);
}
}