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.

Checking for flag status

Other Parts Discussed in Thread: MSP430G2253

Hello

Sorry to ask a simple question here, what is the syntax to check for flag status

I have taken an example from the book MSP microcontroller basics

#include <msp430g2253.h>

#define LED_0 BIT0
#define LED_1 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
LED_DIR = LED_0 + LED_1;
LED_OUT &= ~(LED_0 + LED_1);

TACTL = TASSEL_2 + MC_2 + ID_3 + TACLR;

while(1)
{

   //check for timer A TAFIG interrupt bit, if activated toggle LED 
    while(TACTL_bit.TAIFG == 0)  //what is the syntax to check bit status
     {}

     TACTL_bit.TAIFG = 0  //same here
     LED_OUT ^= LED_0|LED_1;
}

}

Thank you!

Jason

 

  • Hi Jason,

    You can do this by doing a bitwise and to isolate the flag you are interested in.

    while ((TACTL & TAIFG) == 0)

    HTH,

    Barry

  • It is a matter of definition. Specifically, the definition of TACTL_bit.TAIFG.

    If the header files you used does not define TACTL_bit.TAIFG, then the compiler will generate an error msg to tell you it is not defined. If it is defined, but not correctly, then the compiler will not generate error msg but will generate incorrect code without telling you so. In this case, when you run the code, it will no do what you think it should do.

    Most header files I have seen do not have definition for TACTL_bit.TAIFG. But they do have definition for both TACTL and TAIFG. in this case, you could use (TACTL & TAIFG) to access that flag (bit).

  • Guys, thank you for the reply!

    Btw, how do i clear the interrupt flag. I need to modify TAIFG = 0. Also where can i read up more about the syntax of CCS so I can read up myself. This is so different from NXP and arduino ide that im familiar with. Sorry for asking so many newbie questions and Thanks again! 

    Regards,

    Jason

  • Ng Jason said:
    Btw, how do i clear the interrupt flag. I need to modify TAIFG = 0.

    See TACTL as a byte variable and TAIFG as a bit in it.
    TACTL &= ~TAIFG;
    will ADN all bits set in TACTL with the bits set in the inverse of TAIFG (which is all bits but the TAIFG bit) and therefore clear the TAIFG bit. To set it, the opposite is to be done:
    TACTL |= TAIFG;

    When modifying bitfields (a value that consists of more than one bit), you need to mask the field first:
    TACTL = (TACTL & ~MC_3) | MC_1;

**Attention** This is a public forum