Jump to content
hellhunt

Tiva C tm4c123gxl Interrupt

Recommended Posts

Hi:

 

I trying to use the GPIO interrupt feature but until now I was unable to make it work. Below the code that I'm using. I have verified the external set-up (an external push button) and is correctly placed. When I debug it, I wait until reaches to the infinite loop (while()) and then I push the button on the pin D7 to try to cause an interrupt but it never enters to the interrupt handler. Any help will be appreciated. I have also declared the handler on the vector table. Below the code:

void initInterrupt(){
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	//	GPIOIntRegister(GPIO_PORTD_BASE);

	GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_7);
	GPIOPadConfigSet(GPIO_PORTD_BASE,GPIO_PIN_7,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
	GPIOIntTypeSet(GPIO_PORTD_BASE, GPIO_PIN_7,GPIO_RISING_EDGE);

	GPIOIntEnable(GPIO_PORTD_BASE, GPIO_PIN_7);
	GPIOIntClear(GPIO_PORTD_BASE, GPIO_PIN_7);
	IntMasterEnable();
	IntEnable(INT_GPIOD);
	//	HWREG(0x40004410) = 0xFF;
}

void IntGPIOdHandler(void){

	if (GPIO_PORTD_DATA_R & 0b10000000)
	{
		counter++;
		LCDWriteText("Incr. Counter: bobo ", 1, 0);
	}

	GPIOIntClear(GPIO_PORTD_BASE, GPIO_PIN_7);
}


int main(void){

	counter = 0;

	SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); // 400MHz / 2 / 5 (SYSCTL_SYSDIV_5) = 40MHz

	initLCD();
	LCDCommand(0x0C);
	LCDWriteText("*------------------*", 0, 0);
	LCDWriteText("Incr. Counter: ", 1, 0);
	LCDWriteText("Decr. Counter: ", 2, 0);
	LCDWriteText("*------------------*", 3, 0);

	initInterrupt();

	while(1);
}

Share this post


Link to post
Share on other sites

Note that pin PD7 is one of the two NMI pins.  So you have to do a special incantation before you program it.

 

#include "lm4f120h5qr.h"
    GPIO_PORTD_LOCK_R = GPIO_LOCK_KEY;
    GPIO_PORTD_CR_R = 0xFF;
    GPIO_PORTD_LOCK_R = 0;

 

Since you are pulling the pin up and doing an interrupt on rising edge, presumably you have the switch connected to ground, and want to get the interrupt when the switch is released?  

You are taking care of debounce with external circuitry?

Have you tried just reading the GPIO to detect when the button is pressed (and when not)? (i.e. to be sure that the interrupt handling is only problem).

Share this post


Link to post
Share on other sites

Btw after SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

you need about 3 clock cycles before you access the GPIO registers without a a fault ISR happening (sometimes it doesn't happen). SysCtlDelay(3); would be enough for any peripheral

Share this post


Link to post
Share on other sites
On 9/29/2014 at 2:50 AM, hellhunt said:

)can every one help me to make a traffic lights with interrupt ,timer and u art 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...