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.

MSP430F5632: Pin assignment and changing pin value

Part Number: MSP430F5632
Other Parts Discussed in Thread: MSP430F147

I have much code written for other compilers and I want to use the same code for the MSP430F5632. I want to use this style code DisplayRESET = 0; where DisplayRESET is a single pin.  Here is the struct and #defines I have:

struct BitMapping
    {
    unsigned
    Bit0:1,
    Bit1:1,
    Bit2:1,
    Bit3:1,
    Bit4:1,
    Bit5:1,
    Bit6:1,
    Bit7:1;
    }CHR;

#define  Port1_2Base     0x200
#define  Port2OUTCHAR      ( * (char *)Port1_2Base + 0x03)
#define  Port2OUT                  ( * (struct BitMapping *)Port1_2Base + 0x03)

#define  Port5_6Base        0x240
#define  Port5OUT                 ( * (struct BitMapping *)Port5_6Base + 0x02)
#define  Port6IN                     ( * (struct BitMapping *)Port5_6Base + 0x01)
#define  Port6OUT                 ( * (struct BitMapping *)Port5_6Base + 0x03)

#define  Port7_8Base        0x260
#define  Port7IN                      ( * (struct BitMapping *)Port7_8Base + 0x00)
#define  Port7OUT                  ( * (struct BitMapping *)Port7_8Base + 0x02)


#define    DisplayCD    Port6OUT.Bit6
#define    DisplayCE    Port7OUT.Bit7
#define    DisplayWR    Port7OUT.Bit6
#define    DisplayData  Port2OUT.CHR
#define    DisplayRD    Port6OUT.Bit7
#define    DisplayRESET Port5OUT.Bit6

When I compile, everywhere I use a display pin like:

DisplayCD = 0;

I get:

Description    Resource    Path    Location    Type
#42 expression must have arithmetic or pointer type    DisplayRoutines.c    /HRX MSP Ccode/MSP HRX CCODE    line 89    C/C++ Problem

I have not found any examples of pins being used like this.  It's all:

DisplayCD |= BIT6;

or

DisplayCD &=~BIT6;

What do I need to do to use:

DisplayCD = 0;

  • Have you tried *DisplayCD?

  • Just tried it, doesn't work.

  • Hi David,

    This is in interesting question. I'm unsure if there is an easy way to do this on MSP430. The reason is a bit set/clear requires a readback of the GPIO PxOUT register. Hence the need for "|=" (which is just x = x | y).  As far as I know there isn't a single C operation that can do this. 

    The BitMapping struct is neat but I've never seen the ":1" notation before. Can you point me at a reference that describes how this works?

    What compiler/MCU have you been able to use this software paradigm with?

    Regards,

    Evan

  • Standard C. It is a bitfield. Section 6.9 (pg 149) in K&R 2ed. 8^)

  • Quadravox with an MSP430F147 and MSP430F2402

    Is there a setting in the compiler I'm missing or something?

    My computer with the Quadravox died so I'm trying to move all my code to TI's code composer.

  • FOUND IT!!!

    Compiler does not like calculating addresses. Just by chance I tried:

    #define  Port5OUT          ( * (struct BitMapping *)0x242)
    #define  Port6IN              ( * (struct BitMapping *)0x241)
    #define  Port6OUT          ( * (struct BitMapping *)0x243)

    and my errors went away.  Somehow calculating the address works in  msp430f5632.h which is part of the compiler.

  • Hi David, 

    I was able to make it work with a couple modifications to your original code:

    #include <msp430.h>
    
    
    struct __attribute__((__packed__)) BitMapping
        {
        unsigned
        Bit0:1,
        Bit1:1,
        Bit2:1,
        Bit3:1,
        Bit4:1,
        Bit5:1,
        Bit6:1,
        Bit7:1;
        }CHR;
    
    #define  Port1_2Base     0x200
    #define  Port2OUT        ( (struct BitMapping *)Port1_2Base + 0x03)
    
    
    
    int main(void)
    {
      WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT
    
      P2DIR |= 0xFF;
    
      while (1)
      {
         Port2OUT->Bit5 = 1;
         __delay_cycles(1000);
         Port2OUT->Bit5 = 0;
         __delay_cycles(1000);
      }
    
    }

    The key changes:

    1. Use struct __attribute__((__packed__)) BitMapping to get the compiler to understand the bit packing intention
    2. Removed the * in front of the Port2OUT inside the #define
    3. Use the '->' notation instead of '.'

    I was able to see the pin toggel in my example :) Happy coding.

    Evan

**Attention** This is a public forum