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.

ERROR define bit on msp430FR5739?



I'm trying to use Msp430 with Graphic LCD, 

my code error when i assign a name for a bit Port 2 ( out), i have take a photo about this,

i assign name follow library_have:

I don't know why, please help me!

thank you,

  • P2OUT2 = ~P2OUT2; is obviously wrong. P2OUT2 is 0x0004, so the line is translated into "0x0004 = ~0x0004;"

    For the other errors, well, here RW is translated into P2OUT_bit.P2OUT5. owever, there is no variable named P2OUT_bit. There is an unnamed union that has a member named P2OUT_bit.
    And since the union has no name, it is inaccessible.

    This is also the reason why you don't get an error about P2OUT being defined twice (once in the MSP430 headers): your P2OUT is a member of the union.

    On MSPGCC your code gives a warning "undefined struct/union that defines no instances" and an error "P2OUT_bit undeclared"

    The following should work:

    __no_init volatile union
    {
      unsigned char OUT;
      struct
      {
        unsigned char BIT0 :1;
        ...
      } OUT_bits;
    } P2 @0x0203;

    #define RW P2.OUT_bits.BIT5

    However, on some compilers bitfield are word size, extending the union size (and the access width of OUT_bits) to word size. Which won't give the expected results on an odd memory address (the MSP will silently ignore the LSB and access PORT1 instead).

    Also, the use of bitfileds may lead to less efficient code. And pbfuscate possible side-effects of a read or write operation. Two reasons why they are deprecated for hardware registers.

**Attention** This is a public forum