UART Interruptions

Forum related to ERIKA Enterprise and RT-Druid version 2

Moderator: paolo.gai

Post Reply
nestor
Newbie
Posts: 6
Joined: Tue Feb 09, 2010 5:03 pm

UART Interruptions

Post by nestor » 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:

Code: Select all

#include "mcu/microchip_dspic/inc/ee_uart.h"
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:

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);
Then, I define the callback function like this:

Code: Select all

void UART_Rx_cbk(EE_UINT8 data)
{
	if (data == 0x01)
	{
                // led on
		LATBbits.LATB14 = 1;
	}
	else
	{
                // led off
		LATBbits.LATB14 = 0;
	}
}
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:

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;
	}
I'm doing well? What is the correct way? Thanks!!

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re: UART Interruptions

Post by paolo.gai » Fri Nov 16, 2012 11:50 am

The idea of the driver is that the function is called in the context of an ISR2 every time a character arrives. You should not use any register of the UART inside the callback... the serial driver is supposed to take care of that.

If the serial driver does not take care of that, then it's a bug and if you find any bug a patch is always welcome...

Ciao,

PJ

nestor
Newbie
Posts: 6
Joined: Tue Feb 09, 2010 5:03 pm

Re: UART Interruptions

Post by nestor » Fri Nov 16, 2012 7:43 pm

OK! Thanks! I have configured as you tell me and it works, but it seems that it is only capable to receive only 4 characters. I have configured for setting interrupt flag bit when a single character is received.

The interrupt is actived for the first 4 characters that I send from my PC, and later it isn't actived.

Do you know why can it be? Thanks!

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re: UART Interruptions

Post by paolo.gai » Sat Nov 17, 2012 10:29 am

Please check first if the standard demo we ship in the package works fine. There are two you can try:

pic30 / Flex Demo Board / Console Demo

pic30 / Flex Multibus Board / Serial demo

If they do not work, then the problem is in the hardware (check the connections...). If they work, then the problem is in your software (check how these demo works...)

Ciao,

PJ

Post Reply