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.

msp430 pin numbers

Hello everyone,

today i've started to play with msp430 launch pad, my very first experience with microprocessors ever :). I got a bit confused though, because the of the pin numbering. The led blinking example says:

// Since we want to blink the on-board red LED, we want to set the direction of Port 1, Pin 0 (P1.0) as an output

// We do that by writing a 1 on the PIN0 bit of the P1DIR register
// P1DIR = <PIN7><PIN6><PIN5><PIN4><PIN3><PIN2><PIN1><PIN0>
// P1DIR = 0000 0001

but when load up the tutorial code into the device, with a slight changes, say i alter the code

// P1DIR = 0000 0010

it shlould make the PIN2 blink, so on he board it is the P1.1 pin where i shlould connect the external led to blink. But it actually makes P1.3 to blink.

I did not figure out, what am i getting wrong. I have M430g2553 device plugged there (20pins).

Thanks for the answers.

Jan

  • Hi Jan

    There is probably more to that question than what you have said.

    Basically there are two things involved:

    1. Setting the direction of the pin.
    2. Setting the output value of the pin.
    3. Setting the functionality of the pin.
    Thus you should have something like this in the code somewhere:
    P1DIR |= BIT1;      // This will make P1.1 an output
    P1OUT |= BIT1;     // This will set the output of P1.1 high
    P1OUT &= ~BIT1;  // This will set the output of P1.1 low
    And finally, withouth seeing the actual code I can only assume that this does not use RS232? If it does, I believe that the Rx and Tx pin is on P1.1 and P1.2 of the launchpad. In this case if the RS232 functionality is selected, it will overwrite the standard GPIO functionality, and will not work at all for blinking lights. You can tell this if you see any lines that look something like this:
    P1SEL |= (BIT1 | BIT2);   // This will set the functionality of the pin.
    Cheers
    Wynand
  • Jan ���alud said:
    // P1DIR = 0000 0010
    it shlould make the PIN2 blink,

    First, this would be Pin1, not Pin2. Pin2 would be 0000 0100 :)

    Then, this instruciton only sets the direction of the pin (input =0, output = 1). It doesn't set the output value. For changing the outpu value, P1OUT is used. (0= low, 1= high).

    Teh values are not pin numbers, they are bitmasks. Each bit represents a different pin. So you don't writ ethe number of the pin you want to control, you write 8 individual bits for 8 individual pins.

    Writing 3 means setting pin 0 and 1 and clearing the other 6. ORing 3 into the register means setting Pin0 and 1 and keeping the others as they are. And ANDing (&=) 3 means keeping pin0 and 1 in their current state and clearing all others.

  • Although it may seem complicated for no reason, how to work with the I / O is very powerful.
    In principle there are four main registers, PxDIR, PxSEL, PxOUT, ​​PxIN (the x is the port number).
    Register PxDIR, set the direction of each port bit (keep in mind that the number of bit, does not necessarily correspond to the number of a connecting pin, i.e. is like have two pins: a "logical" pin and a "electric" pin), set the direction, is neither more nor less than to establish the pin associated with that bit is used either as input (by setting the bit to 0) or an output (by setting the bit to 1).
    Each of the pins of each port is assigned one or more functions besides GPIO. PxSEL register, allows you to select whether the pin in question will be used as GPIO (assigning zero to the corresponding bit), or in the special function (assigning 1).
    Finally, ports PxIN and PxOUT, correspond directly to the logical values ​​present on each pin. A 1 in a bit means that the associated pin is high, while a 0 in a bit, set the associated pin low.

    To change one bit values ​​without changing the rest, using the logical operations OR and bitwise AND, with the XOR operation can reverse the current state of the bit.

    e.g.

    P1DIR = 0x0F;      // In the port 1, the low nibble is set as ouput, the higher nibble as input

    P2OUT |= 0x04;   // Set the bit 2 to high, in the port 2, whitout change all other bits

    P3SEL = 0x01;   // In the port 3, the bit 0 is asigned as special function, the rest, as GPIO.

    P4OUT &= ~0x02;  //In the port 4, the bit 1 is cleared, whitout change all other bits

    var_input = P1IN;   // var_input is asigned whit the logic state on the input port 1

    P3OUT ^= 0x01;  // bit 0 of output port 3 is inverted, whitout change all other bits


    I hope this review has been helpful.


**Attention** This is a public forum