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/MSP430F4152: variable is changed by system

Part Number: MSP430F4152


Tool/software: Code Composer Studio

Hi,

This is my code below, I have a problem that I do not know how to solve it, plz help me.

The problem is that system will change my variable.

How can I solve it? Can I declare a RAM zone? Can I use the register of MSP430,such as R15, R14.....

The code have not finished yet.

my code:

//***********************************************************************************************
//* Use to control Panasonic MINAS, get loadcell value and position information *
//* MODE 1 is work with PC via UART(BR=9600), *
//* PC control FSA325 and FSA325 control MINAS *
//* *
//* ------------------------------------------------------------------------------------- *
//* | < MODE 1 > ------------------------------------------------------------ | *
//* | | < MODE 1 > -------------- | | *
//* | ------ | -------- SIGN.PULSE --------- | ---------- | | | *
//* | | | | | | =============> | Driver | ==> | |Panasonic | | | | *
//* | | | | | | --------- | | MINAS | | | | *
//* | | | UART | | | | | | | | | *
//* | | | mode/info | | | | ---------- | | | *
//* | | PC | ==========> | | FSA325 | position information | | counter | | | | *
//* | | | run/stop | | | <============================= | | | | | | *
//* | | | | | | loadcell value | ---------- | | | *
//* | | | loadcell | | | <============================= | | loadcell | | | | *
//* | | | <========== | | | | | | | | | *
//* | ------ position | -------- | ---------- | | | *
//* | | -------------- | | *
//* | ------------------------------------------------------------ | *
//* ------------------------------------------------------------------------------------- *
//***********************************************************************************************
#include "msp430f4152.h"
#include "interface.h"

#define kP1 1
#define kP2 2
#define kP3 3
#define kP4 4
#define kP5 5
#define kP6 6
#define EE2464Address 0x50
#define Command_Up 0x10
#define Command_Down 0x11
#define Command_Zero 0x12
#define Command_Original 0x15
#define Command_Jog 0x18
#define Command_Set_Position 0x19
#define Command_Up_Down 0x1A
#define Command_Stop 0x00
#define TXD_OK 0x00

//typedef unsigned char u8t;
//typedef unsigned short u16t;

unsigned int Loadcell_value;//measuring count of loadcell
unsigned int flash_state;//to check if data in flash is available
unsigned int LCD_Page;//1=PC master
unsigned int TX_loop;
unsigned int RX_loop;
unsigned short TX_data[100];
unsigned short RX_data[100];
unsigned short operation_command;
unsigned short RX_flag;
unsigned short pulse_stat;
signed long Position;

void Beep(int beep_time);
void Delay(int time);//10ms
//*********
//* Timer *
//*********
void Timer_set(void);
//********
//* UART *
//********
void TX_data_Transform(void);
void RX_data_operation(void);
void Set_UART(void);
//************
//* MOTOR *
//************
void MINAS_Operation(unsigned short Mode);//0=stop 1=up 2=down
//************
//* loadcell *
//************
void Value_Loadcell(void);//get value loadcell
//*********
//* flash *
//*********
void Check_initialize(void);
void Get_flash_value(void);
void Save_flash_value(void);
//*******
//* LCD *
//*******
void initial_LCD(void);
void LCD_POS(unsigned char LCD_X,unsigned char LCD_Y);
void Write_Command(unsigned char command);
void Busy(void);
void DataBus(unsigned char Data);
void Write_Data(unsigned char Data);
void LCD_Page_choose(unsigned int Page);
void LCD_Page1(void);//PC master
//**********************
//* keypad operation *
//**********************
void KeyOP(void);
unsigned char KeyPad(void);

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;// Stop WDT
//**************
//* initialize *
//**************
Check_initialize();//get data of flash and check if load in default value
initial_LCD();
//===================
Beep(1);
//*************
//* main loop *
//*************
while(1)
{
KeyOP();
Value_Loadcell();
LCD_Page_choose(LCD_Page);
switch(LCD_Page)
{
case 1://PC master
if(RX_flag==0)
RX_data_operation();
break;
}
}
}

void Timer_set(void)
{
//timer 0 set
TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0 = 300;
TA0CTL = MC_0; // SMCLK, stop, clear TAR
__bis_SR_register(GIE);
//timer 1 set
TA1CTL = TASSEL_0 + MC_2 + TACLR;//TACLK, up count mode, clear TAR
}

void RX_data_operation(void)
{
unsigned short loop;
operation_command=RX_data[1];
switch(operation_command)//command
{
case Command_Stop:
MINAS_Operation(0);
break;
case Command_Up:
MINAS_Operation(1);
break;
case Command_Down:
MINAS_Operation(2);
break;
case Command_Zero:
break;
case Command_Original:
break;
case Command_Jog:
break;
case Command_Set_Position:
break;
case Command_Up_Down:
break;
}
//***********************
//* reset flag and data *
//***********************
RX_loop=0;
RX_flag=1;
for(loop=0;loop<100;loop++)
{
RX_data[loop]=0;
}
TX_data_Transform();
}

void TX_data_Transform(void)
{
switch(operation_command)
{
case Command_Up:
case Command_Down:
TX_data[0]=0x03;
TX_data[1]=operation_command;
TX_data[2]=TXD_OK;
break;
case Command_Zero:
break;
case Command_Original:
break;
case Command_Jog:
break;
case Command_Set_Position:
break;
case Command_Up_Down:
break;
}
//****************
//* TX operation *
//****************
TX_loop = 0;
IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt
//UCA0TXBUF = TX_data[0];
}

void MINAS_Operation(unsigned short Mode)//0=stop 1=up 2=down
{
switch(Mode)
{
case 0://stop
TA0CTL = TASSEL_2 + MC_0 + TACLR;//stop
break;
case 1://up
P2OUT &= ~SIGN;
TA0CTL = TASSEL_2 + MC_1 + TACLR;// SMCLK, stop, clear TAR
break;
case 2://down
P2OUT |= SIGN;
TA0CTL = TASSEL_2 + MC_1 + TACLR;// SMCLK, stop, clear TAR
break;
}
}

//***keypad***
// --------- snap KP1 -> O O <- Auto KP2
// | LCD | Up KP3 -> O O <- Down KP4
// --------- Func KP5 -> O O <- Memo KP6
void KeyOP(void)
{
unsigned char temp;
temp=KeyPad();
if (temp==kP1)//snap
{
Beep(1);
MINAS_Operation(0);
}
//=================================================
if (temp==kP2)//auto
{
Beep(1);
MINAS_Operation(1);
}
//=================================================
if ((temp==kP3)&&(LCD_Page==1))//up
{
Beep(1);
MINAS_Operation(2);
}
//=================================================
if ((temp==kP4)&&(LCD_Page==1))//down
{
//Beep(1);
}
//=================================================
if ((temp==kP5)&&(LCD_Page==1))//func
{
//Beep(1);
}
//=================================================
if (temp==kP6)//memo
{
//Beep(1);
}
}

unsigned char KeyPad(void)
{
unsigned char keycode,temp;
volatile unsigned i,j;
for (i=0;i<250;i++);
keycode=0; //reset keycode
temp=~(P4IN) & 0x07;
if (temp!=0)
{
switch (temp)
{
case PG1:
for (i=0;i<130;i++);
temp=~(P4IN) & 0x07;
if(temp==PG1)
keycode=kP1;
break;
case PG3:
for (i=0;i<130;i++);
temp=~(P4IN) & 0x07;
if(temp==PG3)
keycode=kP3;
break;
case PG2:
for (i=0;i<130;i++);
temp=~(P4IN) & 0x07;
if(temp==PG2)
keycode=kP2;
break;
}
}
temp=~(P2IN) & 0XE0;
if (temp!=0)
{
switch (temp)
{
case PG4:
for (i=0;i<130;i++);
temp=~(P2IN) & 0XE0;
if(temp==PG4)
keycode=kP4;
break;
case PG5:
for (i=0;i<130;i++);
temp=~(P2IN) & 0XE0;
if(temp==PG5)
keycode=kP5;
break;
case PG6:
for (i=0;i<130;i++);
temp=~(P2IN) & 0XE0;
if(temp==PG6)
keycode=kP6;
break;
}
}
return keycode;
}

void LCD_Page_choose(unsigned int Page)
{
switch(Page)
{
case 1:
LCD_Page1();
break;
}
}

void initial_LCD(void)
{
Delay(1);//10ms
Write_Command(0x38);
Delay(1);//10ms
Write_Command(0x01);//Clear
Delay(1);//10ms
Write_Command(0x0C);//Display On,disable cursor
Delay(1);//10ms
Write_Command(0x06);
Write_Command(0x02);
P4DIR |= BL_EN;
P4OUT &= ~BL_EN;//Backlight ON
}

void LCD_Page1(void)//PC master
{
unsigned short loop0,loop1;//use for display loop
unsigned short loop3,loop4;
unsigned short data[10];
unsigned char table[4][16]= {
//0 1
//0123456789012345
{"FVE MTR+Loadcell"},
{" Loadcell: 1024 "},
{"MODE : PC Master"},
{" "}
};
//***************
//* change data *
//***************
data[0]=Loadcell_value;
//loadcell
data[1]=data[0]%10;//1
data[0]/=10;
data[2]=data[0]%10;//10
data[0]/=10;
data[3]=data[0]%10;//100
data[4]=data[0]/10;//1000
loop4=14;//character array
for(loop3=1;loop3<5;loop3++)//value array
{
switch(data[loop3])
{
case 0:
table[1][loop4]='0';
break;
case 1:
table[1][loop4]='1';
break;
case 2:
table[1][loop4]='2';
break;
case 3:
table[1][loop4]='3';
break;
case 4:
table[1][loop4]='4';
break;
case 5:
table[1][loop4]='5';
break;
case 6:
table[1][loop4]='6';
break;
case 7:
table[1][loop4]='7';
break;
case 8:
table[1][loop4]='8';
break;
case 9:
table[1][loop4]='9';
break;
default:
table[1][loop4]='-';
break;
}
loop4--;
}
//***********************
//* clear meaningless 0 *
//***********************
if(table[1][11]=='0')
{
table[1][11]=' ';
if(table[1][12]=='0')
{
table[1][12]=' ';
if(table[1][13]=='0')
table[1][13]=' ';
}
}
//================================================
//Write_Command(0x01);//Clear
//================================================
for(loop0=0;loop0<4;loop0++)
{
LCD_POS((loop0+1),0);
for(loop1=0;loop1<16;loop1++)
{
Write_Data(table[loop0][loop1]);
}
}
}

void Write_Data(unsigned char Data)
{
Busy();
P1DIR |= RS+RW;
P7DIR |= Enable;
P1OUT |= RS;
P1OUT &= ~RW;
_NOP();
DataBus(Data);
_NOP();
P7OUT |= Enable;
_NOP();
_NOP();
_NOP();
P7OUT &= ~Enable;
P1OUT |= RW;
}

void LCD_POS(unsigned char LCD_X,unsigned char LCD_Y)
{
unsigned char pos;
if (LCD_X==1)
LCD_X=0x80;
else if (LCD_X==2)
LCD_X=0x90;
else if (LCD_X==3)
LCD_X=0x88;
else if (LCD_X==4)
LCD_X=0x98;
pos=LCD_X+LCD_Y;
Write_Command(pos);
}

void Write_Command(unsigned char command)
{
Busy();
P1DIR |= RS+RW;
P7DIR |= Enable;
P1OUT &= ~(RS+RW);
DataBus(command);
_NOP();
_NOP();
P7OUT |= Enable;
_NOP();
_NOP();
_NOP();
P7OUT &= ~Enable;
P1OUT |= RW;
}

void Busy(void)
{
P5DIR &= ~DB7;
P1DIR |= RS+RW;
P7DIR |= Enable;
P1OUT &= ~RS;
P1OUT |= RW;
P7OUT |= Enable;
while (P5IN&DB7);//busy
P7OUT &= ~Enable;
}

void DataBus(unsigned char Data)
{
unsigned char i;
unsigned char temp;
i=0;
for (i=0;i<8;i++)
{
switch (i)
{
case 0:
P5DIR |=DB0;
temp=0;
temp +=Data&0x01;
if (temp&0x01)
P5OUT |= DB0;
else
P5OUT &= ~DB0;
break;
case 1:
P5DIR |=DB1;
temp=0;
temp +=Data&0x02;
if (temp&0x02)
P5OUT |= DB1;
else
P5OUT &= ~DB1;
break;
case 2:
P5DIR |=DB2;
temp=0;
temp +=Data&0x04;
if (temp&0x04)
P5OUT |= DB2;
else
P5OUT &= ~DB2;
break;
case 3:
P5DIR |=DB3;
temp=0;
temp +=Data&0x08;
if (temp&0x08)
P5OUT |= DB3;
else
P5OUT &= ~DB3;
break;
case 4:
P5DIR |=DB4;
temp=0;
temp +=Data&0x10;
if (temp&0x10)
P5OUT |= DB4;
else
P5OUT &= ~DB4;
break;
case 5:
P5DIR |=DB5;
temp=0;
temp +=Data&0x20;
if (temp&0x20)
P5OUT |= DB5;
else
P5OUT &= ~DB5;
break;
case 6:
P5DIR |=DB6;
temp=0;
temp +=Data&0x40;
if (temp&0x40)
P5OUT |= DB6;
else
P5OUT &= ~DB6;
break;
case 7:
P5DIR |=DB7;
temp=0;
temp +=Data&0x80;
if (temp&0x80)
P5OUT |= DB7;
else
P5OUT &= ~DB7;
break;
}
}
}

void Beep(int beep_time)
{
volatile unsigned int i,j;
switch(beep_time)
{
case 0://long beep
for (j=0;j<600;j++)
{
P1OUT |= BZ;//buzzer on
for(i=0;i<15;i++);
P1OUT &= ~BZ;//buzer off
for(i=0;i<15;i++);
}
break;
default://beep for "beep_time" times
for(;beep_time>0;beep_time--)
{
for (j=0;j<200;j++)
{
P1OUT |= BZ;//buzzer on
for(i=0;i<15;i++);
P1OUT &= ~BZ;//buzer off
for(i=0;i<15;i++);
}
for (j=0;j<100;j++)
{
for (i=0;i<48;i++);
for (i=0;i<48;i++);
}
}
break;
}
}

void Delay(int time)//10ms
{
int i,j;
int Delay_time;
for(Delay_time=0;Delay_time<time;Delay_time++)
{
for(i=0;i<50;i++)
{
for(j=0;j<30;j++)
{
_NOP();
}
}
}
}

void Check_initialize(void)
{
unsigned short clear_loop;
//**************
//* Initialize *
//**************
RX_flag=1;
RX_loop=0;
TX_loop=0;
Loadcell_value=0;
operation_command=0;
pulse_stat=0;
Position=0;
for(clear_loop=0;clear_loop<100;clear_loop++)
{
RX_data[clear_loop]=0;
TX_data[clear_loop]=0;
}
Get_flash_value();
if(flash_state != 0xF0)//load in default if there is none data in flash
{
LCD_Page=1;
Save_flash_value();
}
Set_UART();
Timer_set();
//***********
//* set I/O *
//***********
P1DIR |= BZ;//output
P2DIR |= SIGN;
P3DIR |= PULSE;
P3SEL |= Count;
P6SEL |= RXD + TXD;//P6.5,6 = USCI_A0 RXD/TXD
}

void Set_UART(void)
{
volatile unsigned int i;
//************
//* set uart *
//************
FLL_CTL0 |= XCAP11PF;//Configure load caps
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0x47FF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?

UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 0x03;// 32k/9600 - 3.41
UCA0BR1 = 0x00;
UCA0MCTL = 0x06; // Modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register(GIE);
}

void Value_Loadcell(void)
{
int i;
unsigned long Temp_value;
Temp_value=0;
for(i=0;i<1000;i++)
{
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;//ref 1.5v
//ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;//ref 2.5v
ADC10CTL1 = INCH_4;//set ADC port A4.
ADC10CTL0 |= ENC + ADC10SC;// Sampling and conversion start
Temp_value += ADC10MEM;//get value from loadcell
ADC10CTL0 &= ~ENC;
}
Temp_value /= 1000;
Loadcell_value = Temp_value;//get average of loadcell
}

void Get_flash_value(void)
{
unsigned int *Flash_ptr1;//check initialize
unsigned int *Flash_ptr2;//system
Flash_ptr1=(unsigned int *)0x1000;
Flash_ptr2=(unsigned int *)0x1001;

flash_state=*Flash_ptr1++;
LCD_Page=*Flash_ptr2++;
}

void Save_flash_value(void)
{
unsigned int *Flash_ptr1;//check initialize
unsigned int *Flash_ptr2;//system
Flash_ptr1=(unsigned int *)0x1000;
Flash_ptr2=(unsigned int *)0x1001;

FCTL1 = FWKEY + ERASE;//enable erase data in the flash
FCTL3 = FWKEY;//unlock flash
*Flash_ptr1=0;//erase data of flash
*Flash_ptr2=0;
FCTL1=FWKEY + WRT;//enable write data in the flash
//****************************************
//* write data into flash of address set *
//****************************************
*Flash_ptr2++=LCD_Page;
*Flash_ptr1++=0xF0;
FCTL1=FWKEY;
FCTL3=FWKEY + LOCK;//lock flash
}

//***********************************
//* ADC10 interrupt service routine *
//***********************************
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF);// Clear CPUOFF bit from 0(SR)
}

//*****************************************************************
//* TXD interrupt service routine & I2C interrupt service routine *
//*****************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCI0TX_ISR (void)
#else
#error Compiler not supported!
#endif
{
UCA0TXBUF = TX_data[TX_loop++];// TX next character

if (TX_loop == TX_data[0])// TX over?
IE2 &= ~UCA0TXIE;// Disable USCI_A0 TX interrupt
}

//*********************************
//* RXD interrupt service routine *
//*********************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCI0RX_ISR (void)
#else
#error Compiler not supported!
#endif
{
unsigned short loop;
//**********************************************
//* RXD data mode:length+command+data+...+0x00 *
//**********************************************
//**************
//* get length *
//**************
if(RX_loop==0)
RX_data[0]=UCA0RXBUF;
//************
//* get data *
//************
if(RX_loop>=(RX_data[0]-1))//RXD over
{
RX_flag=0;
}
RX_data[RX_loop]=UCA0RXBUF;
RX_loop++;
//*************************************
//* error check *
//* avoid crush *
//* or stuck in RXD interrupt routine *
//*************************************
if(RX_flag==0)//when RXD over, check if data is correct
{
if((RX_data[RX_data[0]-1]!=0x00)||(LCD_Page!=1))//check data and mode
{//if wrong, clear data and reset flag
RX_flag=1;
RX_loop=0;
for(loop=0;loop<100;loop++)
RX_data[loop]=0;
}
}
}

// Timer A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
if(pulse_stat==0)
{
P3OUT &= ~PULSE;
pulse_stat=1;
}
else
{
P3OUT |= PULSE;
pulse_stat=0;
}
}

my header:

#ifndef INTERFACE_H_
#define INTERFACE_H_

//PORT 1
//#define P1_0 0x01
//#define P1_1 0x02
//#define P1_2 0x04
#define BZ 0x08
#define CS1 0x10 //LCD CS1
#define CS2 0x20 //LCD CS2
#define RS 0x40 //LCD DI
#define RW 0x80 //LCD RW

//PORT 2
#define SIGN 0x01
#define EX4 0x02
#define EX3 0x04
#define EX2 0x08
#define EX1 0x10
#define PG6 0x20
#define PG5 0x40
#define PG4 0x80

//PORT 3
#define Reset 0x01
#define SEL 0x02
#define P3_2 0x04
#define Count 0x08
#define EX9 0x10
#define EX8 0x20
#define EX7 0x40
#define PULSE 0x80

//PORT 4
#define PG3 0x01
#define PG2 0x02
#define PG1 0x04
#define BL_EN 0x08
//#define P4_4 0x10
#define PEDAL 0x20
#define AC 0x40
#define Direction 0x80

//PORT 5
#define DB0 0x01
#define DB1 0x02
#define DB2 0x04
#define DB3 0x08
#define DB4 0x10
#define DB5 0x20
#define DB6 0x40
#define DB7 0x80

//PORT 6
#define OV 0x01
#define SCL 0x02
#define SDA 0x04
#define OP_EN 0x08
#define Loadcell 0x10
#define RXD 0x20
#define TXD 0x40
//#define P6_7 0x80
#define I2C_PORT_SEL P6SEL
#define I2C_PORT_OUT P6OUT
#define I2C_PORT_REN P6REN
#define I2C_PORT_DIR P6DIR
#define SDA_PIN BIT2 // UCB0SDA pin
#define SCL_PIN BIT1 // UCB0SCL pin
#define SCL_CLOCK_DIV 0x12 // SCL clock devider

//PORT 7
//#define P7_0 0x01
//#define P7_1 0x02
//#define P7_2 0x04
//#define P7_3 0x08
#define OC 0x10
//#define P7_5 0x20
#define Enable 0x40
//#define P7_7 0x80

#endif /*INTERFACE_H_*/

  • Hi Norton,

    I'd like to better understand your issue so that we can better assist you:
    1. You say that a variable is changed unexpectedly. Which variable is changed, and what is the expected value vs the failing case/changed value?
    2. Can you determine at what point in the program or operation the value changes? To help facilitate this, you can set a breakpoint for halting the debugger based on a particular variable changing or even a particular variable changing to a specific value, instead of halting just on a specific code address. There's information on doing this in "Advanced Debugging using the EEM with CCSv6" www.ti.com/.../slaa393
    3. Observe the .map file (in CCS you can find this in the Debug folder in your project) and find at what address your variable of concern is being placed. Is it near something that you access with a pointer e.g. right after an array like your TX/RX buffers? That could indicate that perhaps there is an off-by-one error somewhere in accessing the array such that you write off the end of it, overwriting the variable value instead?

    Regards,
    Katie

  • Hi Katie:

    Because of some reasons, I must use CCS4 in my company.
    The variable, Position, and some of the others variable are all changed unexpectedly. This is an important value of this project.
    And I have used break-point and step operation to watch the variables, all of the variables that are changed unexpectedly have a some situation.
    This situation is that, the variables are under controlled in my main sub or interrupt service routine.
    Once I call a sub that include some private variables declare, these variable are changed.
    In my opinion, I think the memory of the variables or operations are covered by others. Or they have the same address. Because of that, the variables are changed into same value but when I change the initialize value of the private variable, the variable that changed unexpectedly have the different value.
    So my problem is that, are there any ways that can use to solve the problem of the variables changed unexpectedly?

    Sincerely,
    Norton
  • Hi Norton,

    One problem with the fact that you are using CCS4 is that if this is the result of a very old compiler error I'm not sure how you would get around it...

    Like you said, it sounds like your variables get overwritten by others. It could be that your variables are actually being stored in registers depending on if the compiler thinks they need to be saved or not, and so get blown away by the sub-routine. You could try declaring some of the impacted global variables as volatile to see if they are then preserved.
    Another thing you could do is to use the debug watch window to determine at what address the variables are stored (the watch window should show value and address) when they get changed - does it indicate they are in a register, or in a RAM address?
    Looking at your .map file, which shows the addresses where the affected variables are stored, and comparing with notes of which sub-routine variables are being initialized when the issue occurs, you also may be able to check those addresses as well for a collision.

    Finally, is it just normal variable initialization that is being initialized in the sub-routine, or something you are setting with say a pointer or setting something directly at an address, when the issue occurs? It can be easy to have an address get off when using pointers like this, and the compiler can't really catch that for you. Or the compiler may have placed something at that address if you haven't somehow reserved it e.g. using the linker file or other methods, and that can cause a collision.

    Regards,
    Katie
  • Hi Katie:

    Thanks for applying to me.

    It is true that my ccs version is too old to solve some problems.
    But now, I have already found a way to solve this problem.
    The way to solve is to reduce my variables. I combined some variables together and now the system would not change my variables.

    Still, I have to find a best way for my project. Thanks a lot.

    Sincerely,
    Norton
  • Hi Norton,

    If reducing the number of variables solved the issue it does indeed sound like some sort of memory collision. I would be worried that as your program grows or changes you could run into the same issue again. You may need to check how the variables are getting allocated in the memory as well as making sure you have a large enough stack reserved in your project settings so that you are not having a stack overflow.

    Regards,
    Katie
  • Hi Katie:

    Thanks a lot. I will check about it.

    Sincerely,
    Norton

**Attention** This is a public forum