Search code examples
embeddedmsp430memory-mapping

Using all ports of MSP430 as one big port - is it possible?


It will be more convenient for me to use all the MSP430 ports as one port. I was thinking maybe to overflow the registers until the next memory address, but it's not working (or maybe i'm not doing it right).

To access BIT0 of PORT2, I tried Something like that:

P1OUT |= 0x80000000000;

because in the memory P2OUT (0x0029) is 8 addresses after P1OUT (0x0021), and those are 8bit registers in the middle. so 8x8=64.

I know I can access the P2OUT with an offset like this:

*(char *)(0x0021 + 0x0008)  |=  BIT0;

I want to define myself a list of GPIO's from 1 to 13, and turn them on and off without checking if GPIO11 is on PORT2 or on PORT1, I want one command to do it all.

is is possible?


Solution

  • P1OUT |= 0x80000000000;
    

    This does not work because

    1. you did not count bits correctly:

      P1OUT |= 0x10000000000000000;
      
    2. P1OUT is an 8-bit register, so the compiler would throw away all but the lowest eight bits. You would have to use a data type that is large enough (and the bit you want to set is the 65th bit in memory, so you'd need a type larger than 64 bits):

      *(uint128_t*)&P1OUT |= 0x10000000000000000;
      
    3. There is no 128-bit type.

    You can get what you want with another layer of indirection:

    volatile uint8_t * const ports[] = { &P1OUT, &P2OUT, &P3OUT };
    
    static inline void setGPIO(unsigned int number)
    {
        *ports[number / 8] |= 1 << (number % 8);
    }