3

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.

Curtis
  • 341
  • 6
  • 18
  • Launchpad lacks JTAG, do you mean the 6 pin header with SBW? – Passerby Apr 13 '16 at 04:27
  • 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? – Passerby Apr 13 '16 at 04:42
  • 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. – The Photon Apr 13 '16 at 05:19
  • 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. – Passerby Apr 13 '16 at 05:22

3 Answers3

1

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.

filo
  • 8,801
  • 1
  • 25
  • 46
1

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.

Curtis
  • 341
  • 6
  • 18
  • 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. – Curtis Apr 17 '16 at 02:17
  • Wait. You're OP. I'm assuming you tested this and found that it worked? – Passerby Apr 17 '16 at 02:19
  • 1
    Added results and an additional short helper function to hopefully add credibility to the above answer. – Curtis Apr 17 '16 at 02:25
  • 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. – Passerby Apr 17 '16 at 02:25
  • See the note on page 328 of the x2xx family guide for example. The G2210/30 is the 8 pin version, and this would fail for P1.0, 1.1, 1.3, 1.4, 2.6 and 2.7, as the DIE is the same as the 2211 and 2231 14 pin version. **So please update once you can test on the 28/32 pin 2253, as I would love to confirm this** – Passerby Apr 17 '16 at 02:40
  • 1
    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. – Curtis May 01 '16 at 00:48
  • This doesn't work. Port 3 regs works fine on my msp430g2553 launchpad 20 pin version. I do get the same results using your example above, showPinExistence() returns false for pins from port 3, but that's because the the pinMode/digitalWrite doesn't actually write to/read from the P3 port, but because P3 is not defined internally. What confuses me is that it seemingly works on the 28 pin version for you, which it shouldn't based on what I'm seeing unless you also changed build target in Energia. – user2251965 Oct 29 '22 at 16:53
1

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.

Hans
  • 7,238
  • 1
  • 25
  • 37