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.

CCS/MSP430FR6989: Variable doesn't act the way it should in the debugger (CCS 6.1.0)

Part Number: MSP430FR6989
Other Parts Discussed in Thread: MSP-EXP430FR6989

Tool/software: Code Composer Studio

Hi TI community,

I have an MSP430FR6989 uc, programming it using MSP-EXP430FR6989 launch pad, and I am using CCS 6.1.0

am doing a simple code, where I create an odometer that counts from 0 to 99,999, and then resets again.

This is my code.

#include <msp430.h> 
 
#define DEVELOPMENT 0x5A80
#define ENABLE_PINS 0xFFFE
 
int main(void)
{
    WDTCTL = DEVELOPMENT;
    PM5CTL0 = ENABLE_PINS;//this is needed in order to enable pins
    
    P1DIR = 0x01;
    P1OUT = 0x00;
    
    unsigned int ones, tens, hund, thou, tnth;
    
    unsigned long km = 0;
    
    while(1)
    {
        for(tnth = 0;tnth<10;tnth++)
        {
            for(thou = 0;thou<10;thou++)
            {
                for(hund = 0;hund<10;hund++)
                {
                    for(tens = 0;tens<10;tens++)
                    {
                        for(ones = 0; ones<10;ones++)
                        {
                            km = 10000*tnth+1000*thou+100*hund+10*tens+ones;
                        }
                    }
                }
            }
        }
        
        P1OUT = ~P1OUT;
        km = 0;
    }
 
return 0;
}

I added a breakpoint at P1OUT = ~P1OUT , and pressed the Resume button. (Line 41)

At that line, I see the values of tnth , thou , hund , tens , and ones  are equal to 10 , which is as expected.

But I also expected km = 99999 , but instead I got km = 34463 . Shouldn't km = 99999.

Also

I modified my code, and changed thnth , thou , hund , tens , and ones  to signed int  instead of unsigned int 

when I Run my program, and it reaches the breakpoint, I see km > 4,000,000,000 

Which doesn't make sense.

I believe the problem is with CCS. I searched online, and some people mentioned that CCS is not synchronizing with the microcontroller, if that was the case, how can I fix it.

I would appreciate your help.

Regards,

Forat

  • When I build it, I get the diagnostic ...

    "file.c", line 16: warning #552-D: variable "km" was set but never used

    When I inspect the assembly code generated by the compiler, there is no mention of the variable km.  It is optimized away.  

    I'm not sure of the best fix.  One way is to declare km volatile.

    Thanks and regards,

    -George