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.

How to use the IntRegister() in TM4C123GH6PM?

Today,I want to use the TImer and Interrupt to flip the GPIO In a certain period,and my code follow as:

/**************************************************************************************************************************/

int main(void)
{

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);  //Configure SysCtlClock 40Mhz

 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);                          // GPIOF_pin2
 GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_2);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);                       //Configure Timer
 TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);  

ui32Period = (SysCtlClockGet()/10)/2;                                          //Configure the load value for TIMER0 -> TIMER_A

TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);          //Trigger the interrupt function in 20hz

IntRegister(INT_TIMER0A,Timer0IntHandler);                          // Register a function : Timer0IntHandler()

IntMasterEnable();                                                                   //Enables the processor interrupt
TimerEnable(TIMER0_BASE, TIMER_A);                               //Enables TIMER0 -> TIMER_A

while(1)

{

}

}

void Timer0IntHandler(void)            //  flip the GPIOF_PIN2
{
 // Clear the timer interrupt
 TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

 // Read the current state of the GPIO pin and
 // write back the opposite state
 if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
 {
  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
 }
 else
 {
  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
 }
}

/***********************************************************************************/

  • Hello user4491221,

    Be careful in doing such an action dynamically. This should only be done when no interrupt is active as the use of IntRegister requires relocation of the interrupt address space to the SRAM. If during this time any valid interrupt source is going to be active, it may result in a conflict due to a non-setup interrupt vector.

    Regards
    Amit
  • Hi,

    Your code looks good; however check again the macros used, could be some typing errors. Be sure you modified the startup interrupts vector in startup_ccs.c file.

    Verify your code by placing an interrupt inside timer interrupt and watch if the interrupt is taken.

    Basically, you can live without registring an interrupt, it is not mandatory, except for special cases; your actual test example does not need that, but needs to modify the startup file.

  • Hello Petrei

    It looks like the Interrupt enable has not been called. IntEnable API is missing.

    Regards
    Amit
  • Thanks for your suggestions, Amit.

    Now,I find where ' s wrong to my codes.The mistake is that I didn't enable INT_TIMER0A and I didn't config the TIMER0_BASE for TimerA time out interrupt.

  • Thanks your suggestions,Petrei.
    I use the IntRegister() that don't need to modified the startup interrupts vector in startup_ccs.c file.
    If I use the IntEnable(INT_TIMER0A), I have to modified the startup interrupts vector in startup_ccs.c file.
    Finally,I find The mistake was that I didn't enable INT_TIMER0A and I didn't config the TIMER0_BASE for TimerA time out interrupt
  • Hello Baizeboob,

    Good that now you are up and running.

    Regards
    Amit