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.

register operation

Other Parts Discussed in Thread: MSP430I2041

i have found the following line of code working with many MSP430 devices. But its not working for the davice iam using MSP430i2041

TA0CCTL0_bit.CCIE = 1; Please let me know why it is not working?

is ther any other way to set or reset a perticular bit in a register??

iam using code composer studio v6

Thanks in advance

  • Hi Ashraf!

    Maybe this style of bit access is not implemented for the device. I don't know, I have never used this method, but you can also write

    TA0CCTL0 |= CCIE;

    for setting the CCIE bit in TA0CCTL0. For clearing it, write

    TA0CCTL0 &= ~CCIE;

    Dennis

  • but suppose if i want to do something when an interruppt flag is set, how i can write that with the help of a while loop
  • Hello Ashraf,

    you can do this in this way:

    while (TA0CCTL0 & CCIFG){ }

    So you test for a set interrupt flag. In this case the while-loop is executed as long as CCIFG is set. The same approach works with it-else-statements:
    if(TA0CCTL0 & CCIFG) for testing a set bit
    if(!(TA0CCTL0 & CCIFG)) for testing a not set bit

    Best regards,
    Michael
  • In addition to Michael:

    The method works, of course, although waiting for a flag to be set is, in general, waste of CPU time. But for starting with microcontrollers, this is absolutely OK. But the more important thing when not using interrupts and their vectors is the handling method of the flags. You will have to read about the interrupt generation and clearing of the flags for each module seperately since not all of them are handled in the same way.

    In your case when dealing with the timer you could do the following in your code:

    void main( void )
    {
      ...
    
      while( 1 )
      {
        ...
     
        if( TA0CCTL0 & CCIFG ) // CCIFG is set for TA0CCR0
        {
          // Do something
    
          TA0CCTL0 &= ~CCIFG;  // Clear the interrupt flag
        }
    
        ...
      }
    }

    It is important to clear the interrupt flag manually, otherwise it stays set. If you were using interrupts, then the flag would automatically be cleared for CCR0 when entering the ISR or for CCR1, CCR2, ..., TAIFG when reading the IV inside the ISR (the highest set one is cleared).

    This is, for example, different for the buttons - these flags have to be cleared by the user in every case.

    So you should always have a look into the user's guide for that. The interrupt generation and clearing is normally located just before the register descriptions of the modules start.

    Dennis

**Attention** This is a public forum