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.

MSP430FR2355: bit field questions?

Part Number: MSP430FR2355


Want to create a char (8 bits) where each bit represents a boolean flag T or F.  How do I do this?  Secondly will it only take up one char in memory?  Finally been reading and seems maybe I should use unsigned char?

  • Bitfields are very implementation defined, you really have to try it and see. Unsigned char are the way to go if you want to go this route. I think a better bet is to use a standard unsigned char and roll your own bit setting and testing operations, much like what TI has for the control registers.

  • Well here is my code and it seems to work.....Do you see any red flags:

    Within header file :

    struct userWakeFlags
    {
        volatile unsigned char timerFlag : 1;
        volatile unsigned char adFlag : 1;
        volatile unsigned char keySwitchFlag : 1;
        volatile unsigned char timeMeasureFlag : 1;
    };
    

    Initializing in main:

    struct userWakeFlags flags = {0};
    

    Use in main:

            if (flags.timerFlag) //compare
            {
                flags.timerFlag = F;
    

    The setting to F and T may be red flags?? but it seems to wrk

  • I don't know what F and T are, but that should work. The question is whether it is any more efficient than rolling your own.

  • Plus, you can't set more than one of them at a time. That's the fundamental weakness with defining machine registers that way [Ref Freescale]. And at their best they're nothing but syntactic sugar -- the CPU still has to do a RMW cycle. 

**Attention** This is a public forum