SAM4S xplained Pro enable interrupt on SW0

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

On my SAM4S xplained Pro, I am able to set up an interrupt on PIO_PA14. The pin is normally LOW and when pressing the button, the pin is pulled UP.

 

The SW0 button on PIO_PA2 (on board )is wired the opposite. It is normal HIGH and is pulled DOWN when pressed.

 

In the below code, if I enable the interrupt on PIO_PA2, the code crashes (nothing runs). Any thoughts on what I am doing wrong?

 

// http://asf.atmel.com/docs/latest/sam4s/html/sam_pio_quickstart_use_case_2.html
void setup_interupts(void){

	pmc_enable_periph_clk(ID_PIOA);	

	pio_set_input(PIOA, SW1, PIO_PULLUP);
	pio_set_debounce_filter(PIOA,  SW1, 20);
	pio_handler_set(PIOA, ID_PIOA, SW1, PIO_IT_EDGE, pin_edge_handler);
	pio_enable_interrupt(PIOA, SW1);

	// doesn't work!
	//pio_set_input(PIOA, SW0, IOPORT_MODE_PULLDOWN); // configured in init.c
	pio_handler_set(PIOA, ID_PIOA, SW0,  PIO_IT_EDGE, pin_edge_handler2);
	pio_enable_interrupt(PIOA,  SW0);

	NVIC_EnableIRQ(PIOA_IRQn);	

}

 

This topic has a solution.

"When all else fails, read the directions"

Last Edited: Fri. Jun 2, 2017 - 11:28 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After almost a year I came back to this post after I stumbled upon this post in where a user had a similar problem, which helped me solve mine. In a nutshell, I need to use 1 handler for PIOA and check the index to see which pin was fired:

 

#define SW1 PIO_PA14
#define SW0 PIO_PA2

void setup_interupts(void){	
	pmc_enable_periph_clk(ID_PIOA);	

	pio_set_input(PIOA, SW1, PIO_PULLUP);
	pio_set_debounce_filter(PIOA,  SW1, 20);
	pio_handler_set(PIOA, ID_PIOA, SW1, PIO_IT_EDGE, pin_edge_handler);
	pio_enable_interrupt(PIOA, SW1);	

	pio_set_input(PIOA, SW0, PIO_PULLUP); // configured in init.c
	pio_handler_set(PIOA, ID_PIOA, SW0,  PIO_IT_EDGE, pin_edge_handler);
	pio_enable_interrupt(PIOA,  SW0);
	NVIC_EnableIRQ(PIOA_IRQn);
}

void pin_edge_handler(const uint32_t id, const uint32_t index)
{
	if ((id == ID_PIOA) && (index == SW1)){		
		if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, SW1) ){				
			printf("Button PA14 Pressed\n\r");
		}		
	}	else if((id == ID_PIOA) && (index == SW0)){

		printf("Button PA02 (On board Button was Pressed \n\r");
	}
}

Hope this helps someone!

"When all else fails, read the directions"