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.

CC2530 Timer Interrupt Problem

Other Parts Discussed in Thread: CC2530

Hello,

I have been trying to set the Timer3 in the CC2530 using the SmartRF05 board to generate a periodic interrupt in Modulo Mode every time an overflow occurs. However even though I have applied the settings step by step as specified on the User Guide, it never generates the interrupt, in which all I do is toggle an LED (I monitor this signal with an oscilloscope). I am using IAR Workbench 8051. Could you please take a look at the code and tell me what exactly am I missing?


#include "iocc2530.h"
#include "hal_board.h"
#include "hal_led.h"

#define T8BIT_TICK_FREQ_DIV128      7
#define T8BIT_MODE_MODULO           2
#define T3_COUNT_VALUE              0x7F

#ifndef SH
#define SH(n,m)    (n << (m))
#endif

void main(void)
{

    // Initalise board peripherals
    halBoardInit();

    /***************************************************************************
    * Timer 3
    */
   
    // Connect timer3 interrupt function to corresponding interrupt vector
    //Timer3IntConnect(&Timer3AccIsr);
    //HAL_ISR_FUNCTION(T3_ISR,T3_VECTOR)
     
    /*Start Timer*/
    T3CTL |= 0x10;
   
    /*Set Timer Clock Frequency */
    T3CTL &= ~0xE0;
    T3CTL |= SH(T8BIT_TICK_FREQ_DIV128,5);
   
    /* Set Mode */
    T3CTL &= ~0x03; //Start Timer
    T3CTL |= T8BIT_MODE_MODULO; //Set Modulo Mode
   
    /*Enable OverFlow Interrupt Mask*/
    T3CTL |= 0x08;
   
    /*Disable OverFlow Interrupt*/
    T3CTL &= ~0x08;
   
    /* Set Comp Value (If necessary*/
    T3CC0 = T3_COUNT_VALUE;

    /*Enable Timer3 Overflow Interrupt*/
    TIMIF &= ~0x01; // Clear Flag
    IEN1 |= 0x08; // T3IE = 1

    // Enable Global Interrupts
    EA = 1;
   
    // Main loop
    while (1) { }//while
}//Main


HAL_ISR_FUNCTION(T3_ISR,T3_VECTOR)
{
  halLedToggle(1); 
}

  • Hello Eduardo,

    I've found it just now.

    And you might have already solved it, since it's old post.

    I think your procedures are sometimes redundant and setting sequence is not always correct.

    And some headers provided by sample must be included.

    You need to configure following settings to use timer.

    (1)  Prescaler dividing value setting

    * if you need you can change X'tal

    (2) Interrupt enable setting

    (3) select compare match (compare match value setting) or overflow

    (4) Associate ISR function and interrupt vecter

    (5) Timer interrupt enable (say timer start)

    Concretely speaking, if I use 1 sec timer , I may write followings.

     

    #include "ioCC2530.h"
    #include "hal_int.h"
    #include "hal_types.h"

    static ISR_FUNC_PTR t3_fptr;

        // Timer ticks output as 250 KHz
        CLKCONCMD |= 0x38;

        // prescaler divider value to 128, interrupt enable, repeatedly count from 0x00 to T3CC0
        T3CTL = 0xEA;
        T3CCTL0 = 0x44;
        T3CC0 = compare_Value;
        Timer_3_IntConnect(&Timer3_ISR);
        Timer_3_IntEnable();

     

    void Timer_3_IntConnect(ISR_FUNC_PTR isr)
    {
        unsigned short key;
        HAL_INT_LOCK(key);
        t3_fptr = isr;
        HAL_INT_UNLOCK(key);
    }


    HAL_ISR_FUNCTION(T3_ISR,T3_VECTOR)
    {
       if (t3_fptr != NULL)
       {
            (*t3_fptr)();
       }
    }

    static void Timer3_ISR(void){
      halLedToggle(1); 
    }

    void Timer_3_IntEnable(void)
    {
        IEN1 |=  0x08; // IEN1.T3EN = 1
    }

     

    I hope it'll be for your reference or just learning.

    Thucydides

     

     

     

  • Hi Thucydides,

     

    Please help. Do you have a sample code for 60 second timer? I work on this for quite sometime.

     

    Best regards

    chianho 

     

  • Hi,

    I am having some trouble getting this code to work. First of all, looks like it doesnt have "Start" bit. With that bit pogrammed, now I am able to get the timer interrupt, but something is wrong. it is not 1sec. But back to back. Sounds like INT is due to T3CNT overflow rather than based on compare. Also the timer seems to be moving too fast (Initial programmed value 250K timer tick vanishes for some reason and become 32M). I tried this in non debug mode as well. No help.

    Do you know what could be wrong?

  • Hi TI Team,

    i want to blink the led on CC2530 P0 with 1 sec time, and want to create the delay using timers,

    and i am also working to derive LCD 16x2 on CC2530. Please help me to work this in IAR Work Bench,

    i am facing problems to get work with cc2530 modules because its registers are different from 8051.