This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Interrupt on a port using GPIO_HIGH_LEVEL

I am using Stellaris LM4F120H5QR

I want to get the time of a pulse given as input on PC4 

I have written the following code and also made necessarry changes in startup_ccs.c but still can't get the light blinking on a high pulse , why is this so?

#define PART_LM4F120H5QR
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_timer.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"

unsigned long ul_counter=0;
int check=0;
void
InitConsole(void)
{

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_6);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,0x00);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);

}

void disp()
{
UARTprintf("***************************************************************************\n");
UARTprintf(" Author : A^2 \n");
UARTprintf(" Pulse Width Measurement\n");
UARTprintf(" Update Rate: to be displayed\n");
UARTprintf(" Input Pin: AIN0/PE3\n");
UARTprintf(" Initialising.");

UARTprintf("\n");
UARTprintf("***************************************************************************\n");
}

void Timer_Setup(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 10);
IntMasterEnable();
TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
IntEnable(INT_TIMER0B);
}

void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ul_counter++;
}

void CCPIntHandler(void)
{ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,0xFF);
TimerEnable(TIMER0_BASE, TIMER_B);

check=1;
}

void main(void)


{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);


// Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL.
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);


InitConsole();
disp();
Timer_Setup();

GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_HIGH_LEVEL);
GPIOPortIntRegister(GPIO_PORTC_BASE, CCPIntHandler);


while(1)
{

if((GPIOPinIntStatus(GPIO_PORTC_BASE, 0)==16)&&(check==1))
{
TimerQuiesce(TIMER0_BASE);
Timer_Setup();
check=0;

}


}


}

  • got the code working ; had made a mistake in typing the name of handler in startup_ccs.c.

    but still the part in while(1) is skipped according to me ;debugged through printing values from uart.

  • Anurag Meena said:
    had made a mistake in typing the name of handler

    Typing - as opposed to, "Copy/Paste" - always opens you to such possibility. 

    Mandating, "Copy/Paste" when name/label must be re-used or referenced - avoids this (often maddening) error.  And - should name/label be long or complex - proves much faster as well...

  • The variable check is not marked as volatile, so the compiler assumes its value never changes.

    Any variable that is referenced both within and outside of interrupts must be marked as volatile.

  • Just a quick comment - your clock initialization I think is for 40Mhz, not 20.  PLL is running at 400Mhz, going through a Div 2 divider before hitting the MUX, which you've got set for another 5 divider - so (400 / 2) / 5 = 40.