ISR not working with interrupt vectors

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

Hello,

 

I am trying to use Interrupts for serial communication with ATMEGA4809 Xplained pro evaluation board. For example I want to get this LED control example to work by using the USART1 rx interrupt vector to fill the buffer whenever data is available via serial input. ISR(USART1_RXC_vect) is never called though, when I send serial messages to the board.

 

const char const help_str[]   = "Type on/off to control LED \r\n";
const char const ledon_str[]  = "LED is on\r\n";
const char const ledoff_str[] = "LED is off\r\n";

int help(void)
{
	printf(help_str);
	return 0;
}

int Turn_on_LED(void)
{
	USER_LED_set_level(false);
	printf(ledon_str);
	return 0;
}

int Turn_off_LED(void)
{
	USER_LED_set_level(true);
	printf(ledoff_str);
	return 0;
}

int parseCmd(char *commands)
{
	char *cmds = NULL;

	if ((cmds = strstr(commands, "help"))) {
		help();
	} else if ((cmds = strstr(commands, "on"))) {
		Turn_on_LED();
	} else if ((cmds = strstr(commands, "off"))) {
		Turn_off_LED();
	}

	if (cmds != NULL) {
		return 1;
	} else {
		return 0;
	}
}
char    buf[5]  = {0};
uint8_t buf_pos = 0;
int main(void)
{

	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	// Enable pin change IRQ
	PORTB.PIN2CTRL |= PORT_ISC_BOTHEDGES_gc;

	parseCmd("help\0"); // Print out instructions

	while (1) {
		if (parseCmd(buf) || (buf_pos > 4)) {
			buf[0]  = 0;
			buf_pos = 0;
		}
	}
}

ISR(USART1_RXC_vect){
		buf[buf_pos] = USART1.RXDATAL;
		buf_pos++;
		buf[buf_pos] = 0;
	//}
}

 

The example works just fine when I use this function provided by AtmelStudio, only that this is blocking the while(1) loop, which I can not use for my project.

uint8_t USART_0_read()
{
	while (!(USART1.STATUS & USART_RXCIF_bm))
		;
	return USART1.RXDATAL;
}

 

What am I missing?

 

 

Thanks a lot in advance

This topic has a solution.
Last Edited: Wed. Oct 21, 2020 - 04:32 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

VOLATILE