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.

Transmitting Timer2 Values in CC2530

Other Parts Discussed in Thread: CC2530

Hello,

I am currently using the Basic RF and HAL RF from the CC2530 Software Examples User's Guide. I am trying to transmit the Timer 2 values over RF but the payload are always zero when I am trying to read the timer values from the registers. If I set the payload to be any arbitrary integer, like 0xAA, I can see it transmitted in the Packet Sniffer. Here is my settings on transmitting the Timer 2 values:

   T2MSEL &= ~0x77; 
    pTxData[0] = T2M0;
    pTxData[1] = T2M1;
    pTxData[2] = T2MOVF0;
    pTxData[3] = T2MOVF1;
    pTxData[4] = T2MOVF2;

I know that my Timer 2 is working and I can transmit any arbitrary integer using RF. Am I doing something wrong? Please help

 

- JC de Dios

  • The code you show here looks OK.

    When you say that you know that your timer 2 is working, does that mean that you have verified that the timer has a value different from 0 when this reading is done? If not, check that you have actually started the timer before you execute the code above. If you started it using synchronous start, you need to wait for T2CTRL.RUN to be 1 before the timer is running. Note however that synchronous start should only be used if you previously stopped the timer synchronously (i.e., after coming from PM1 or PM2). See Section 22.4.3 of the user guide for more detail on synchronous start.

    Note that when you extract a full 40-bit timer value as in the code you provided, you should set T2CTRL.LATCH_MODE to 1 to ensure that the overflow value is consistent with the timer value.

  • Thanks hec,

    Yes I have set the latch mode on, and I am currently blinking an LED at 1Hz using Timer 2 interrupt for testing purposes. Does the payload initialization matter? The payload variable is initialized as:

    static uint8 pTxData[APP_PAYLOAD_LENGTH];

    I have set the payload length to 5. I am trying to change the variable type but the Basic RF and HAL RF functions does not allow me

    - JC de Dios

  • The initialization of the buffer should not matter as long as you do not declare the same variable in several source files.

    However, you did not answer my question on whether you know that the timer is running at the time that you read the timer value. The fact that you have the LED blinking shows that the timer works, but are you sure that the timer is read after the LED blinking started, and not only right after reset?

    Have you tried using the debugger to look at the contents of the pTxData buffer in the transmitting device? And have you tried setting a breakpoint at the time the timer is read to see what the timer registers are at that time (and that the code is actually executed)?

    If these things don't help you, you will probably have to post some more of your code in order to get help.

  • Um, yes I think I am sure that the timer is read after the LED blinking started. I have the Timer 1 transmit the Timer 2 values every 0.25 seconds using Timer 1 interrupt, while I have a blinking LED using Timer 2 interrupt. I can see LED blinks every second and a packet is transmitted every 0.25 second but the payload is always zero. This is how I initialized timer 2:

    //initialize timer2 for local time
        T2MSEL |= 0x20; //overflow period
        T2MOVF0 |= 0xE8;
        T2MOVF1 |= 0x01;
        T2MOVF2 |= 0x00;
        T2MSEL &= ~0x77; // access to timer count value and overflow counter
        T2CTRL |= 0x08; // latch mode
        //timer interrupt
        T2IRQF &= ~0x08; // clear overflow counter interrupt flag
        T2IRQM |= 0x08; // enable overflow counter interrupt
        IRCON &= ~0x04; //clear Timer2 interrupt flag
        IEN1 |= 0x04; // Timer2 enable interrupt

        T2CTRL |= 0x01; //start Timer 2

  • This looks mostly OK, except that it seems that you are using synchronous start when you start the timer the first time, which is not recommended, because the timer then starts with an unpredictable value.

    Also, you are using the |= declaration in cases where a simple = would be better. It probably works because of the reset value of the registers, but logically, it would be better to replace the T2MOVx statements with =. Also when setting T2MSEL you should be careful that you know the initial state when using |= (I would either have done T2MSEL = (T2MSEL & 0x07) | 0x20; or just T2MSEL = 0x20; if you don't mind changing the lower bits of the register.)

    I don't think these small issues are the cause of your problems, though.

    You should use the debugger to make sure that the values that you read out of the timer are actually what goes into the RF transmit routine. It could for instance be that the values are overwritten, or that you have duplicate definitions of the Tx buffer. It is however impossible for me (or other people on this forum) to go further into that without seeing more of your code.

  • Thanks hec, I followed your advice on the small issues and tried using a debugger and I found my value conflict. Thank you very much  :)