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.

My fist simple example to evaluate the CCS Cloud compiler was a disaster

Other Parts Discussed in Thread: MSP430G2553

Hardware: launchpad MSP-EXP430g2 Rev 1.5

Session ID 1454963993441_00001379

#include "msp430g2553.h"

void delay(unsigned int );

/*
* main.c
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = BIT0 ; //  Red LED
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;

while (1)
{
P1OUT |= BIT0; // red led
delay (65000);
P1OUT &= ~BIT0; 
delay (65000);

}

return 0;
}

void delay(unsigned int k)
{
unsigned int i;
for(i=0;i<k;i++);
}

WHEN I RUN THE PROGRAM THE LED IS CONSTANT ON

With a scoop I see a square wave of about 100 kHz. (???)

The code is ok, I tested it with the IAR workbench tool.

The red led blinks with a frequency of about 2 Hz

  • user52302 said:
    void delay(unsigned int k)
    {
    unsigned int i;
    for(i=0;i<k;i++);
    }

    The compiler optimizer is free to eliminate the delay loop, because there are no observable side effects.

    To force the compiler to generate a delay loop either declare i as volatile, or use the __delay_cycles intrinsic. 

  • Thank You Chester Gillon,
    YOU HELPT ME A LOT!
    you wrote: "there are no observable side effects" that is not correct.
    I see now the red led blinking with a frequency of about 2 Hz ( instead of about 100 kHz, what means continue on)