Search code examples
cmicrocontrollerinterruptmsp430

C - prevent interrupt activiation - MSP430


I wrote the following code to initialize the buttons on my MSP430 microcontroller:

    void Initialize(void){

       P1REN |= 0x02;                          
       P1OUT |= 0x02;                         
       P2REN |= 0x02;                          
       P2OUT |= 0x02;                          
       P1IE |= 0x02;                           
       P2IE |= 0x02;                              
       P1IFG &= ~0x02;                         
       P2IFG &= ~0x02;                         

       TA1CTL = TASSEL_1+ID_0+MC_2+TACLR;      
       TA1R = 40000;                         

       _BIS_SR(GIE);                           

    }

How do I prevent that the line P1IFG &= ~0x02; provokes an Interrupt? I'm new to microcontroller programming and read that this line provokes an interrupt if something changes in the P1IE register.

Thanks for your help!


Solution

  • The User's Guide says:

    Writing to P1OUT, P1DIR, P2OUT, or P2DIR can result in setting the corresponding P1IFG or P2IFG flags.

    However, this code clears the PxIFG flags before enabling the interrupts globally (GIE), so an unintentional interrupt cannot happen.