AVR Studio 6 stops like there was a breakpoint, but don´t

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

I have not used Atmel Studio 6 for a while and yesterday I started a new project. Well, I´m trying to get some NMEA strings from a GPS and I get stuck in a weird problem. Probable I´m overlooking something or doing some dumb error, but I give up and could not realize what is going on. So if someone can point me what is wrong would be nice.

The code:

uint8_t rx_serial ()
{
	if (flag_usart_rx==1)
	{
		flag_usart_rx=0;
		if (uart_getchar=='R' || flag_rmc==1)
			{
			rx_serial_string[prt_serial] = uart_getchar;			// Move string da UART no array
			prt_serial++;
			flag_rmc=1;
			}
		if (prt_serial==50)
			{
			prt_serial=0;
			flag_rmc=0;
			}
	}

return (0);
}
	UBRR1H = (unsigned char) (baud >> 8);	// define baud
	UBRR1L = (unsigned char) baud;
	UCSR1B = (1<<TXEN0) | (1<<RXEN0);			// Habilita TX RX
	UCSR1C = (1<<UCSZ10)|(1<<UCSZ11);			// 8 bit
	UCSR1B |= (1 << RXCIE1);
	sei();
	prt_serial=0;
	while(1)
    {
	rx_serial();
    }
}

ISR (USART1_RX_vect)
{
	uart_getchar = UDR1 ; // Fetch the received byte value into the variable " ByteReceived "
	flag_usart_rx=1;
}

When I run this code it will stop just after the return:

return (0);
} <<<< Stops here!

It is like I have a break point, but I´m not. 

Any idea what is causing this?

Thank you!

 

Good Soldering JRGandara

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

One more bit of info. I added more code and now the studio stops further. 

Good Soldering JRGandara

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

gandara wrote:

When I run this code it will stop just after the return:

return (0);
} <<<< Stops here!

Sounds like it's crashing on exiting the function - maybe you're trashing the stack...?

 

Quote:

			rx_serial_string[prt_serial] = uart_getchar;			// Move string da UART no array
			prt_serial++;
			flag_rmc=1;

You don't seem to have any check to stop prt_serial running off the end of the array?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But running step by step, I see when the pointer reach 50 and is reset. Using the code in the chip, without the IDE, everything runs fine. The problem is happening only in the IDE environment. 

Good Soldering JRGandara

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

Which debugger are you using, and which AVR?

 

If you are using JTAG, you can increase the clock frequency of the JTAG which may help.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

I´m using Atmega164p with JTAG ICE MKII. If I add more code, the "breakpoint" stops early! Very annoying!

Good Soldering JRGandara

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

Post your entire code(or a zip if it is that big).  These little snippets are not going to help at the moment.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

awneil wrote:
You don't seem to have any check to stop prt_serial running off the end of the array?

Sorry:  must've been blind - I can see it now!

 

		if (prt_serial==50)
			{
			prt_serial=0;
			flag_rmc=0;
			}

But you have a nasty Magic Number there - is the array correctly defined...?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Problem solved.  I checked and there was a newer Atmel Studio version. I installed and the bug disappeared. Now the code works fine in teh IDE and on trhe chip. Thank you guys for teh suggestions. 

Good Soldering JRGandara