mbeals 74 Posted July 19, 2013 Share Posted July 19, 2013 I'm in the process of figuring out how interrupts and timers work on this board, so I wrote a short program to adjust the brightness of the blue led by clicking on either button. The left button trips the interrupt just fine and does what it is supposed to....but the right button will not, even though it is configured identically. I even tried a simpler version of the code in which would only interrupt pin 0 or pin 4, and even then it will not interrupt on pin 0. I also tried clearing both interrupts right before entering the main loop, and it didn't help. It has to be something stupid simple, but I can't see it. The code is below #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "inc/hw_ints.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "driverlib/timer.h" #include "driverlib/pin_map.h" #include "driverlib/interrupt.h" volatile unsigned long ulPeriod = 1000; volatile unsigned long dutyCycle = 250; int main(void) { // 40 MHz system clock SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); /*Pwm the blue LED*/ // Configure PF2 as T1CCP0 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinConfigure(GPIO_PF2_T1CCP0); GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_2); // Configure timer SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod -1); TimerMatchSet(TIMER1_BASE, TIMER_A, dutyCycle); // PWM TimerEnable(TIMER1_BASE, TIMER_A); /* Configure buttons for input */ GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4); GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_FALLING_EDGE); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4); /* Configure interrupt for buttons */ IntEnable(INT_GPIOF); IntMasterEnable(); while(1){} } void IntGPIOF(void) { if (GPIOPinIntStatus(GPIO_PORTF_BASE, GPIO_PIN_0) & GPIO_PIN_0) { GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_0); TimerMatchSet(TIMER1_BASE, TIMER_A, dutyCycle+=100); if(dutyCycle >= ulPeriod - 1) dutyCycle = 0; }else{ GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_4); TimerMatchSet(TIMER1_BASE, TIMER_A, dutyCycle-=100); if(dutyCycle < 100 ) dutyCycle = ulPeriod - 1; } } cry_viem 1 Quote Link to post Share on other sites
igor 163 Posted July 19, 2013 Share Posted July 19, 2013 Port F pin 0 has special function (NMI), so you have to do a special incantation to program it as an input. See drivers/buttons.h in stellarisware for an example HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; cry_viem 1 Quote Link to post Share on other sites
mbeals 74 Posted July 19, 2013 Author Share Posted July 19, 2013 Thanks. Worked perfectly. What exactly does NMI do in this context (what utility is there in binding it to this pin to begin with)? Quote Link to post Share on other sites
igor 163 Posted July 19, 2013 Share Posted July 19, 2013 I would guess the reason for putting a push button on the non-maskable interrupt input is sort of like the programmer's button on the Apple II. It gives a way to get the processor back to some known code (if it wanders off into never never land), of course you have to write the handler. Note that the same button is also wired to the !Wake input - again making it into a kind of wake up and pay attention button (but not as drastic as reset). (The special incantation means your errant code is highly unlikely to change the programming of that pin.) Also, there are a limited number of pins, and a lot of functions, so things get overlaid. They should do a better job at documenting it though. The launchpad manual should have a warning under user switches and buttons, pointing out the need for a special incantation to program PF0. (Of course there are a number of things the launchpad manual should cover more clearly, like PD7 wiring should be mentioned under USB). Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.