problems with usarts and interrupt receive on uc3b0256

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone,

Am hoping you can help, have spent 2 days searching the forum and Google with no success.

I have 2 custom boards built using uc3b0256 chips.
usart0 and usart1 are connected to 2 max3232 chips with TX, RX, RTS, CTS lines for both usarts.

I have setup both usarts to use interrupt driven receive, using the example code here http://asf.atmel.no/avr32/driver...

I have usart1 sending data received to usart0 and usart0 sending data received to usart1

If I have the board plugged onto a pc, everything works beautifully, and I get no problems.

However, the moment I try plug usart0 on the first board, to usart1 on the second board, or any other combination of plugging them together (using a crossover cable that connects TX to RX, RX to TX, RTS to CTS, CTS to RTS) then each board will freeze up the moment the

Enable_global_interrupt();

function is called, or if I have the

((volatile avr32_usart_t *)&AVR32_USART0)->ier = AVR32_USART_IER_RXRDY_MASK;

((volatile avr32_usart_t *)&AVR32_USART1)->ier = AVR32_USART_IER_RXRDY_MASK;

after the Enable_global_interrupt(); function, then it freezes on setting the receive interrupt enable flag for the usart

It will only freeze for the usart that is connected to another board. But not if the same usart is connected to the pc.

I think I may have a hardware problem, but have been unable to prove it.

Please see my code here

#include "stdio.h"
#include "usart.h"
#include "string.h"
#include "intc.h"
//other necessary includes to make it compile


void debugmsg(char *msg)
{


	usart_write_line_direct(&AVR32_USART0,msg);		//Port B
	usart_write_line_direct(&AVR32_USART1,msg);		//Port A

}




__attribute__((__interrupt__)) void usart0_int_handler(void)
{
	int c, stat;
	stat = usart_read_char(&AVR32_USART0, &c);
	if (stat == USART_SUCCESS)
	{
		usart_putchar_direct(&AVR32_USART1,c);		//send the received char out the other port
	}
}







__attribute__((__interrupt__)) void usart1_int_handler(void)
{
	int c, stat;
	stat = usart_read_char(&AVR32_USART1, &c);
	if (stat == USART_SUCCESS)
	{
		usart_putchar_direct(&AVR32_USART0,c);		//send the received char out the other port
	}
}





int main(void)
{

	pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);		//Switch to oscillator 0

	static const usart_options_t USART_OPTIONS =
	{
			.baudrate     = 9600,
			.charlength   = 8,
			.paritytype   = USART_NO_PARITY,
			.stopbits     = USART_1_STOPBIT,
			.channelmode  = USART_NORMAL_CHMODE
	};


	//note:usart0 is Port B on the PCB
	static const gpio_map_t USART0_GPIO_MAP =
	{
	     {AVR32_USART0_RXD_0_1_PIN, AVR32_USART0_RXD_0_1_FUNCTION},
	     {AVR32_USART0_TXD_0_1_PIN, AVR32_USART0_TXD_0_1_FUNCTION}
	};

	//note:usart1 is Port A on the PCB
	static const gpio_map_t USART1_GPIO_MAP =
	{
	     {AVR32_USART1_RXD_0_0_PIN, AVR32_USART1_RXD_0_0_FUNCTION},
	     {AVR32_USART1_TXD_0_0_PIN, AVR32_USART1_TXD_0_0_FUNCTION}
	};

	gpio_enable_module(USART0_GPIO_MAP, sizeof(USART0_GPIO_MAP) / sizeof(USART0_GPIO_MAP[0]));		//setup the physical lines the usart is on
	gpio_enable_module(USART1_GPIO_MAP, sizeof(USART1_GPIO_MAP) / sizeof(USART1_GPIO_MAP[0]));		//setup the physical lines the usart is on

	usart_init_rs232(&AVR32_USART0,&USART_OPTIONS,FOSC0);		//init port A
	usart_init_rs232(&AVR32_USART1,&USART_OPTIONS,FOSC0);		//init port B

	Disable_global_interrupt();		//call to compiler.h
	INTC_init_interrupts();			// Initialize interrupt vectors. --- call to intc.h


	INTC_register_interrupt(&usart0_int_handler, AVR32_USART0_IRQ, AVR32_INTC_INT0);	//register interrupt for usart0
	INTC_register_interrupt(&usart1_int_handler, AVR32_USART1_IRQ, AVR32_INTC_INT0);	//register interrupt for usart1


	((volatile avr32_usart_t *)&AVR32_USART0)->ier = AVR32_USART_IER_RXRDY_MASK;	//enable interrupt for usart0
	((volatile avr32_usart_t *)&AVR32_USART1)->ier = AVR32_USART_IER_RXRDY_MASK;	//enable interrupt for usart1


	Enable_global_interrupt();		//call to compiler.h


	debugmsg("+Info:Entering main loop ...\r\n");
	while(TRUE);
	return 0;
}

I saw another post http://www.avrfreaks.net/index.p...
that seems to describe a problem similar to what I am having, it says its because of a missing exception.S file, however I have tried including this, it compiles fine, and gives the same behavior. It also does not explain why it works perfectly with the PC and not with another board.

For further info, I am using AVR32 Studio 2.1.0 with the Built in AVR32-SoftwareFramework-AT32UC3B-1.4.0 Release Framework. Unfortunately my boss wont let me upgrade to a new AVR32 Studio at this time, so I need to make it work with this one.

Any guidance any of you can offer would be greatly valued.

Thanks,

Steed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't understand what you want to do exactly, as why there are two messages sent in your "degugmsg" method.

Ok, then I haven't found this problem up to now but like that I think about checking if CTS and RTS lines have good states at start point. Maybe you have already check this point ?
cpu

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Thanks for your reply. I was under the impression that I was not using the RTS/CTS in this current code as USART0_GPIO_MAP and USART1_GPIO_MAP do not have the RTS/CTS lines and I am calling usart_init_rs232 instead of usart_init_hw_handshaking ... am I right in making this assumption or not ?

The debugmsg function is supposed to broadcast the message out of both ports so that it does not matter which one I connect the PC to.

Thanks,

Steed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

sorry for this very late reply, have you solve the problem ?

cpu

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hiya,

Sorry, I did not see your post immediately. I managed to figure the problem out as a overrun error because I had too much code in my rx interrupt trying to interpret what I had received. I moved to using circular buffer, and calling the usart_reset_status function in the framework if I detected an overrun or other rx error. This seems to have made everything work nicely.

However I now have another problem on these sad boards that when the board is out in a noisey environment (monitoring stuff in a factory) it will run for a while and then the atmel completely freezes. I can tell this because I am toggling an led in a timer counter interrupt, and both the interrupt and the main loop stops at the same time. I thought this may be a decoupling problem, but I have decoupling on both the 3.3v and 1.8v supplies, so this is confusing me.
If you have any ideas or advice, please let me know.

Thanks,

Steed.