UART Interruptions
Posted: Thu Nov 15, 2012 7:37 pm
Hello,
I'm trying to develop a program for reading from UART port by interruptions using the library provided with eclipse in:
I have implemented a callback function but I don't understand how it works. For example, I start the port and then I assign the callback function:
Then, I define the callback function like this:
Is this the way to use it? Or I have to read the data value from the U1RXREG register? That's how I think of how to implement this second way:
I'm doing well? What is the correct way? Thanks!!
I'm trying to develop a program for reading from UART port by interruptions using the library provided with eclipse in:
Code: Select all
#include "mcu/microchip_dspic/inc/ee_uart.h"
Code: Select all
EE_uart_init(EE_UART_PORT_1, 57600, EE_UART_BIT_STOP_1 | EE_UART_BIT8_NO, EE_UART_CTRL_SIMPLE);
EE_uart_set_rx_callback(EE_UART_PORT_1, &UART_Rx_cbk, EE_UART_RX_INT_SINGLE);
Code: Select all
void UART_Rx_cbk(EE_UINT8 data)
{
if (data == 0x01)
{
// led on
LATBbits.LATB14 = 1;
}
else
{
// led off
LATBbits.LATB14 = 0;
}
}
Code: Select all
void UART_Rx_cbk(EE_UINT8 data)
unsigned short valor;
if (U1STAbits.OERR)
{ // Receiver buffer has overflowed
U1STAbits.OERR = 0;
return;
}
if (U1STAbits.URXDA)
{ // Receiver buffer has data. At least one more character can be read
valor = U1RXREG & 0x00FF;
if (valor == 1)
{
// LEDs ON
}
else
{
// LEDs OFF
}
}
// reset RX interrupt flag
IFS0bits.U1RXIF = 0;
}