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.

MSP430FR2355: CCS has no macro value for TIMER_B2_BASE

Part Number: MSP430FR2355

I have two timers that are working just fine. The code to init the B1 timer is:

/* Configure TimerB1 to generate 100 Hz Clock */
void jiffyClockInitTimerB1(void){
    Timer_B_initUpModeParam param = {0};
    param.clockSource = TIMER_B_CLOCKSOURCE_SMCLK;
    param.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_48;       // 16uS / 62.5 KHz
    param.timerPeriod = 624;             //625 ticks = 10 mS / 100 Hz
    param.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_ENABLE;
    param.captureCompareInterruptEnable_CCR0_CCIE = TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
    param.startTimer = true;
    Timer_B_initUpMode(TIMER_B1_BASE, &param);
    HWREG16(TIMER_B1_BASE + OFS_TBxCTL) &= ~(TBIE);     // Turn off overflow (goes to zero) IRQ
}

This compiles and works just fine. Now I want to use the B2 timer, and have this code to get it running:

void sineWaveInitTimerB2(void){
    Timer_B_initUpModeParam param = {0};
    param.clockSource = TIMER_B_CLOCKSOURCE_SMCLK;
    param.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_12;       // SMCLK at 3 MHz  4uS / 250.5 KHz
    param.timerPeriod = 71;             // 284uS --> 3.52 KHz  / 8  =440 Hz
    param.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_ENABLE;
    param.captureCompareInterruptEnable_CCR0_CCIE = TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
    param.startTimer = true;
    Timer_B_initUpMode(TIMER_B2_BASE, &param);
    HWREG16(TIMER_B2_BASE + OFS_TBxCTL) &= ~(TBIE);     // Turn off overflow (goes to zero) IRQ
}

  When I try to compile this code, I get an error that TIMER_B2_BASE is undefined.

I added this macro at the top this source file:

#define TIMER_B2_BASE (*((volatile uint16_t *)((uint16_t)0x0400 + (0x0000))))

It now compiles, but, no luck seeing the timer run (I get no IRQs).

Any idea why there are valid macros for TIMER_B0_BASE and TIMER_B1_BASE but not for TIMER_B2_BASE  ?

FWIW, the interrupt handler for this is a copy of one that works with Timer 1. It looks like:

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER2_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMER2_B0_VECTOR)))
#endif
void TIMER0_B2_ISR(void){
    // to DEBUG, pulse the P2.2 bit so we can see when we take timer interrupts and see how long it takes
 GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN3);

    // Important safety tip: the CCIFG interrupt flag is automatically reset when the TBxCCR0 IRQ is serviced
 //    Timer_B_clearTimerInterrupt(TIMER_B0_BASE);
     HWREG16(TIMER_B2_BASE + OFS_TBxCCTL0) &= ~(CCIFG | COV);        // COV is a safety
     HWREG16(TIMER_B2_BASE + OFS_TBxCTL) &= ~TBIFG;        // "counter went to zero" interrupt flag, saf

 GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN3);        // exit timer irq DEBUG
}

Note that there was no problem on compile with the

#pragma vector=TIMER2_B0_VECTOR

statement.

  • According to my copy of msp430fr2355.h the canonical name is TB2_BASE rather than TIMER_B2_BASE:

    >#define __MSP430_BASEADDRESS_TB2__ 0x0400
    >#define TB2_BASE __MSP430_BASEADDRESS_TB2__

    TIMER_B[0/1]_BASE are defined in a legacy.h, which I suppose was overlooked when they came up with an MSP430 with more than two TimerB-s.

    You can see how this works by right-clicking on TIMER_B1_BASE (in your code) and then "Go To Definition".

  •    changing to TB2_BASE did it, I can see the timer interrupts.

      When I  right click in on TIMER_B1_BASE in the existing code, I don't see a "Go To Definition" option, but that's OK.

      Changes to core entries in a .h file are always a challenge. Perhaps TI can add the entry in the legacy.h. for the next user.

      It does take a lot of time to come up to speed on the massive number of include files, macros, "code in ROM", and register names, especially when there is all the effort in CCS to let you move between processors and have less code re-work to do. It is worth it, between this ability to hop around to different chip varients and slowly building up my own libraries, I've used 4 variants of the MPS430FRxxxx family in 5 different projects and 3 different packages.

    This solves my problem, thank you for your reply. I now return to my normally scheduled debugging program already in progress !

**Attention** This is a public forum