3
\$\begingroup\$

I am using a Launchpad to program an MSP430G2553 controller. I use it for debugging. This controller has 20 pins. However, the end goal here is to run my program on an MSP430G2553IPW28R controller. This controller has 28 pins instead of 20.

I'm using pins P3.0 and P3.1 on the 28 Pin Controller for some LEDs. And my launchpad controller doesn't have those pins. I need to determine which controller the code is running on.

I will be using my launchpad's JTAG pins to program the 28 pin controller. So, the question is, how can I programmatically determine which of the 2 controllers my code is running on, and put some kind of #define in place to use pins P3.0, P3.1 when running on the 28 pin controller and pins P2.1 and P2.2 when running on the launchpad controller. I don't want to have comment and uncomment lines of code each time I switch from one processor to the other...

Please note, I'm using Energia as my development environment.

\$\endgroup\$
4
  • \$\begingroup\$ Launchpad lacks JTAG, do you mean the 6 pin header with SBW? \$\endgroup\$
    – Passerby
    Commented Apr 13, 2016 at 4:27
  • \$\begingroup\$ As far as I recall, you can't simply try toggling the pins, as while they are not broken out, they are still implemented in hardware. You shouldn't need to uncomment multiple lines. Make a set of if defined, and you would only have to change a single line when you switch packages. If defined A, define xyz as 123 else if defined B, etc. There may still be a compile time check for package or signature though. What compiler or ide are you using? \$\endgroup\$
    – Passerby
    Commented Apr 13, 2016 at 4:42
  • \$\begingroup\$ You don't have to comment and uncomment code for different configurations. Just add a -D 20PIN or -D 28PIN to the the build settings, and #ifdef's around the code for each choice. \$\endgroup\$
    – The Photon
    Commented Apr 13, 2016 at 5:19
  • \$\begingroup\$ Are you willing to sacrifice one of the extra 8 pins, to use as a bootstrap/run time check? set port 3 pin 7 as input with pull-up. If the pin is tied to ground on the board, use 3.0 and 3.1. Since you can't tie that pin low on the 20 pin package, you will know which package is use. To minimize current draw, you wwould change the pin to output low after the check is done at start up. \$\endgroup\$
    – Passerby
    Commented Apr 13, 2016 at 5:22

3 Answers 3

1
\$\begingroup\$

Depending on project complexity and size of the MCU I use from 1 to 3 pins for "PCB identification" with external pull-down resistors. Resistors are mounted depending on the board revision. Application inside the MCU looks at these pins at startup and determines what to do.

It helps even more if you have several products with some differences allowing you to have a single binary image for all hardware revisions.

\$\endgroup\$
1
\$\begingroup\$

IMHO the most preferred option is to look for a chip ID in the documentation. Most modern chips provide an internal register with the chip type and revision. You could use that to drive your logic.

For MSP430 family I have been able to find some core IDs in the BSL documentation (page 37). However these only limit to the family die and do not distinguish between chip packages. You could still try to test and verify if there is any differences.

Alternatively you could use physical board changes, like adding pull-up/downs on certain pins that can be software tested or tying pins low/high.

\$\endgroup\$
1
\$\begingroup\$

The method below will tell you if a pin exists on the controller. So, to determine if we're using a 20 or a 28 pin controller, select a Digital Pin that is > 20 and pass it as the parameter to the function below. If it returns true, you have a 28 pin controller. If it returns false, you have a 20 pin controller. I tested this using my MSP430G2553 Launchpad and have the following results:

  showPinExistence(2);
  showPinExistence(3);
  showPinExistence(5);
  showPinExistence(6);
  showPinExistence(7);
  showPinExistence(8);
  showPinExistence(11);
  showPinExistence(15);
  showPinExistence(18);
  showPinExistence(21);
  showPinExistence(22);
  showPinExistence(23);


void showPinExistence(int pin)
{
  Serial.print("Pin ");
  Serial.print(pin);
  Serial.print(" Exists: ");
  Serial.println(pinExists(pin)?"True":"False");
  Serial.flush();
}

bool pinExists(int pin)
{
    bool lowResult;
    bool highResult;

    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
    lowResult = digitalRead(pin);

    digitalWrite(pin, HIGH);
    highResult = digitalRead(pin);

    return lowResult != highResult;
}

Here's the output for LaunchPad with MSP430G2553 (20 Pin):

Pin 2 Exists: True
Pin 3 Exists: True
Pin 5 Exists: True
Pin 6 Exists: True
Pin 7 Exists: True
Pin 8 Exists: True
Pin 11 Exists: True
Pin 15 Exists: True
Pin 18 Exists: True
Pin 21 Exists: False
Pin 22 Exists: False
Pin 23 Exists: False

Here's the output for MSP430G2553 (28 Pin):

Pin 8 Exists: True
Pin 9 Exists: True
Pin 10 Exists: True
Pin 11 Exists: True
Pin 12 Exists: True
Pin 13 Exists: True
Pin 14 Exists: True
Pin 15 Exists: True
Pin 16 Exists: True
Pin 17 Exists: True
Pin 18 Exists: True
Pin 19 Exists: True
Pin 20 Exists: True
Pin 21 Exists: True
Pin 22 Exists: True
Pin 23 Exists: True

I had to start with pin 8 because it didn't like when I attempted to set 2-7 as output pins :-) Anyway, the point is that you can attempt to set pin 23 as an output pin and write and read its value to determine if the chip you're using is a 20 pin, or if it has more than 20 pins. I don't have a 32 pin chip, but I would imagine that you could test on a pin greater than 28 to make a determination if it is a 32 pin chip.

Now, after ALL that I've said. Since writing this, I discovered that there is now 28pin support on GitHub. I am now using it and referring to pins with their proper P3_0, P2_0 notation instead of directly by Pin number and this seems to be working just fine now.

\$\endgroup\$
7
  • \$\begingroup\$ Pins 21,22,23 return false in the above function when using a 20 pin package. I'll test it on a 28 pin package in a couple days. \$\endgroup\$
    – Curtis
    Commented Apr 17, 2016 at 2:17
  • \$\begingroup\$ Wait. You're OP. I'm assuming you tested this and found that it worked? \$\endgroup\$
    – Passerby
    Commented Apr 17, 2016 at 2:19
  • 1
    \$\begingroup\$ Added results and an additional short helper function to hopefully add credibility to the above answer. \$\endgroup\$
    – Curtis
    Commented Apr 17, 2016 at 2:25
  • \$\begingroup\$ I'm un-downvoting, as the data sheet seems to indicate that the Port 3 is completely excluded on the 20 pin package, implying a different Wafer Die is used. This seems weird. I know for a fact that this, if used for pins P2.0-P2.5 on the 14 pin MSP430s will not work, as the die is the same as the 20 pin package. \$\endgroup\$
    – Passerby
    Commented Apr 17, 2016 at 2:25
  • 1
    \$\begingroup\$ I have added output for a 28pin MSP430G2553 which indicates the existence of pins 21-23 where the 20pin version showed those pins as false. \$\endgroup\$
    – Curtis
    Commented May 1, 2016 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.