Jump to content
Aconicks

MSP430G2452 - Delayed start after uploading program with Energia

Recommended Posts

Hello,

I am experiencing a frustrating problem which I couldn't find an answer to anywhere online so far, I apologize if a related question was posted before and I didn't find it.

I have  TI MSP-EXP430G2 Launchpad with an MSP430G2452 on it and I'm trying to upload a basic program (the Blink example) with Energia.

After the program has been successfully uploaded the program is not run immediately on the chip and the led doesn't start blinking. Instead there is a long delay (30sec to a few minutes) between powering the device on and the start of the execution. There don't seem to be any errors on compilation/upload. 

On the other hand, I have tried using Code Composer Studio instead and there the program starts running immediately without any problems.

I would really appreciate if anyone has some idea what could be the problem.

Thanks in advance.

Share this post


Link to post
Share on other sites

Have you tried the reset button after upload? Or disconnecting and reconnecting?  If so, does the blink program begin on one of those events?

Are you running identical code in both cases?  Is the CCS version an import of the Energia project, or are you running the TI CCS blink code and something else in Energia?

Post some code...

Share this post


Link to post
Share on other sites

Thank you for replying.

I have tried both the reset button and disconnecting/reconnecting the device. On both scenarios the outcome is the same. The program starts executing after a long delay on Energia and immediately on CCS.

The code I ran on CCS and Energia are not identical since these are different softwares but both the separate codes are the blink example codes provided with each environment without any changes on my side (just import the example project and run).

The codes are the following:

CCS blink example:

#include <msp430.h>				

int main(void) {
	WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer
	P1DIR |= 0x01;					// Set P1.0 to output direction

	for(;;) {
		volatile unsigned int i;	// volatile to prevent optimization

		P1OUT ^= 0x01;				// Toggle P1.0 using exclusive-OR

		i = 10000;					// SW Delay
		do i--;
		while(i != 0);
	}
	
	return 0;
}

 

 

Energia Blink Example:

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(RED_LED, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(RED_LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(RED_LED, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

 

I assume that since the codes both do essentially the same thing (Maybe up to the time between blinks) they are pretty much identical in their core (under the different native syntax and libraries) so I really don't see why there would be any difference on execution.

 

I have also tried creating an Energia Sketch in CCS but it told me that it doesn't support my chip, which is weird, considering I am able to run Energia code separately.

If I can provide you with any more information let me know.

Share this post


Link to post
Share on other sites

This is due to the code trying to detect if a 32.768 kHz crystal  is present. This is done so that the power management code can use the optimal clock source during sleep to get the lowest power. With that said, I have never seen more than a few seconds delay. You can turn detection off by commenting out some lines in the core. Instructions below:

Make sure you upgrade the core to the latest (1.0.3) using the Energia boards manager (Tools->Board->Boards manager).

To avoid the delay in startup put the following at the bottom of your Sketch:

#ifdef __cplusplus
extern "C" {
#endif
void enableXtal() {
  // avoid startup delay
}
#ifdef __cplusplus
}
#endif

This avoids the crystal startup code from being called and instead your version of it is called which does nothing in this case.

Share this post


Link to post
Share on other sites
14 hours ago, energia said:

This is due to the code trying to detect if a 32.768 kHz crystal  is present. This is done so that the power management code can use the optimal clock source during sleep to get the lowest power. With that said, I have never seen more than a few seconds delay. You can turn detection off by commenting out some lines in the core. Instructions below:

Make sure you upgrade the core to the latest (1.0.3) using the Energia boards manager (Tools->Board->Boards manager).

To avoid the delay in startup put the following at the bottom of your Sketch:


#ifdef __cplusplus
extern "C" {
#endif
void enableXtal() {
  // avoid startup delay
}
#ifdef __cplusplus
}
#endif

This avoids the crystal startup code from being called and instead your version of it is called which does nothing in this case.

Thank you so much! This seems to solve the problem and the code does run immediately! 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×