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 registrate a Interrupt-Handler for a Timer on a Lm3sb92 evaluationskit

Prodigy 20 points

Replies: 1

Views: 2848

hallo,

I am new here und i am from cameroon.

I try to togglen the on-Board LED all Second.

I try to use Timer0 like my Clock.

I don t know why it is not goes like i want it.

Please help me.

Regards Christian

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

unsigned char a = 0x00;
unsigned char maske = 0x01;
volatile unsigned long software_timer = 0;  // Ein Software_timer
volatile int software_timer_lock = 0 ;      // schlüssel des Software_timers

void
Timer0IntHandler(void)
{
    //
    // Clear the timer interrupt.
    //
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    //
    IntMasterDisable();

     if(software_timer_lock)
     {
       software_timer--;
     }

       IntMasterEnable();
}

void delay (int a){
     // Time to wait
    software_timer = a ;
    // Start to count
    software_timer_lock = 1    ;
    // Wait a s
    while(software_timer != 0)
    {       
    }
    // count stop
    software_timer_lock = 0    ;
}

int
main(void)
{
    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    //
    // Enable the peripherals used by this application.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    // Configure the LED as an output and turn it on.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);

    //
    // Enable processor interrupts.
    //
     IntMasterEnable();

     TimerIntRegister(TIMER0_BASE, TIMER_A, Timer0IntHandler);

    //
    // Configure the two 32-bit periodic timers.
    //
     TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
     TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());

    //
    // Setup the interrupts for the timer timeouts.
    //
     IntEnable(INT_TIMER0A);
     TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    //
    // Enable the timers.
    //
    TimerEnable(TIMER0_BASE, TIMER_A);

    while(1){

    // GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0);

        delay(10);      // wait about 10 s
    a = maske^a;
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, a);    // LED togglen

    }

}

1 Reply

  • We typically just statically specify the interrupt handlers in our start up files, because we rarely ever need to have dynamically allocated interrupt handler.   However some tools force you to have to call the IntRegister functions for the various interrupt handlers.

    What device and tools are you using with your project?

    If you check the startup_gcc.c for example you would just place the name of your interrupt handler in the location reserved for Timer 0 subtimer A.

    Find the section of the interrupt table that had the timer interrupt handlers and they are probably currently set to IntDefaultHandler as shown here.

    ...

        IntDefaultHandler,                                // Timer 0 subtimer A
        IntDefaultHandler,                                // Timer 0 subtimer B
        IntDefaultHandler,                                // Timer 1 subtimer A
        IntDefaultHandler,                                // Timer 1 subtimer B

    ...

    You just need to replace IntDefaultHandler with Timer0IntHandler in your case as show below

    ...

        Timer0IntHandler,                                 // Timer 0 subtimer A
        IntDefaultHandler,                                // Timer 0 subtimer B
        IntDefaultHandler,                                // Timer 1 subtimer A
        IntDefaultHandler,                                // Timer 1 subtimer B

    ...

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.