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.

MSP430F2131 + TIMERA interrup problems.

Other Parts Discussed in Thread: MSP430F2131

 

 Hi,

 

  Im making a program that have to capture a sequence of bits generated on P1.1 when i press a button. So im making a Capture/Compare based program, but i simply cannot enter the interrup routine. The code is:

 

#include <msp430f2131.h>
#include <intrinsics.h>                  // Intrinsic functions
#include <stdint.h>                      // Integers of defined sizes

#define BITTIME 900                      // Cycles of MSCLK per bit , 1,1MHz
#define HALFTIME (BITTIME /2)             // Cycles for half a bit

uint8_t RXBitCount = 0;                  // Count bits received
uint16_t RXShiftReg;                     // Shift register for reception

void main (void)
{
    P1DIR &= ~BIT1;                        // Set port1.1 as input
    P2DIR |= BIT4;                        // Set port2.4 as output   
    P1SEL = BIT1;                         // P1.1 = S2 to Timer_A CCI0A
   
    BCSCTL1 = CALBC1_1MHZ;                    // Set DCO to 1MHz
    DCOCTL = CALDCO_1MHZ;
   
    WDTCTL = WDTPW | WDTHOLD;             // Stop watchdog timer

    CCTL0 = CM_2 | CCIS_0 | SCS | CAP | CCIE; // Capture/Compare configs

    TACTL = TASSEL_2 | ID_0 | MC_2 | TACLR;
    for (;;) {                             // Loop forever with interrupts
        //__low_power_mode_0 ();
        _nop();
    }
}

#pragma vector = TIMERA0_VECTOR
__interrupt void TIMERA0_ISR (void)
{
   
    P2OUT ^= BIT4;
    CCTL0 &= ~ CCIFG;

    if(CCTL0 & CAP){
        CCTL0 &= ~ CAP;
        RXBitCount = 16;
        TACCR0 += HALFTIME;
    }else{
        switch (RXBitCount) {
            case 16:                     // Start bit
                if (CCTL0 & SCCI) {
                    CCTL0 |= CAP;         // Abandon reception
                } else {                 // Correct: proceed to receive data
                    TACCR0 += BITTIME;  // Wait for complete bit time
                    --RXBitCount;         // Update bit counter
                }
                break;
            case 0:                     // Stop bit
                CCTL0 |= CAP;             // Return to capture mode
                P2OUT ^= BIT4;
                break;   
            default:                     // Data bit (lsb first), cases 1-15
                RXShiftReg >>= 1;         // Shift data , clear msb for new bit
                if (CCTL0 & SCCI) {
                    RXShiftReg |= BITF; // Set received bit if high
                }else{
                    RXShiftReg &= ~BITF; // Set received bit if low   
                }
                TACCR0 += BITTIME; // Wait for complete bit time
                --RXBitCount; // Update bit counter
                break;
       
        }
    }
}


   I would be glad if you could help me solving this.

Thank u in advance,

Tiago

  • Try set the GIE bit in SR.

  • old_cow_yellow said:
    Try set the GIE bit in SR.

    Very good suggestion. I believe, without enabling interrupts, interrupts are ... well ... not enabled? :)

    Tiago Bonfim said:
        for (;;) {                             // Loop forever with interrupts

    A clear case of wishful thinking

    Tiago Bonfim said:
            //__low_power_mode_0 ();
            _nop();


    If the NOP was placed there for a debugger breakpoint: it won't work with LPMs. Due to the pipelined structure of the MCU, the breakpoint will be triggered the very moment LPM is entered, and NOT after the ISR has been triggered and LPM ended. For a breakpoint after an LPM, two NOPs are needed with the breakpoint on the second.

**Attention** This is a public forum