Hi Every one,
i want to retain data after power loss,and i have almost gone lot of threads in the forum, but i didn't achieve what i need!
So i have decided to post it agian pl kindly let me know what is the fault.
Here was my plan to know the variable data is stored during power loss or not
in main's while loop using a switch performing write operation,next read that variable if the value read matches with the known value led is ON if not OFF.
Now if i press the switch with the launch pad connected to the programming pins of the controller ,the read value is matching and led is ON,and if i remove the programming pins form the launch pad it is OFF.
i have developed this code with the help of TI sample example code of flash in MSP430G2553 and from forum posts
#include <msp430g2553.h>
int x;
int value;
int state;
int *Flash_ptr1;
//int *Flash_ptr2;
// Function prototypes
void write_SegC (int value);
int Flash_Read(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
P2DIR |= BIT1;
P2OUT &= ~BIT1;
P2DIR |= BIT4;
P2OUT &= ~BIT4;
P2DIR &= ~BIT0;
P2SEL &= ~BIT0;
P2SEL2 &= ~BIT0;
P2REN |= BIT0;
while(1)
{
if((P2IN&0x01)==0)
{
P2OUT |= BIT4;
write_SegC(1);
__no_operation(); // SET BREAKPOINT HERE
}
else
{P2OUT &= ~BIT4;}
x=Flash_Read();
if(x==1)
P2OUT |= BIT1;
else
P2OUT &= ~BIT1;
}
}
void write_SegC (int value)
{
FCTL2 = FWKEY + FSSEL0 + FN1;
FCTL3 = FWKEY;
FCTL1 = FWKEY + ERASE;
Flash_ptr1=(int *) 0x1000;
*Flash_ptr1 = 0;
FCTL1 = FWKEY + WRT;
*Flash_ptr1 = value;
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
}
int Flash_Read(void)
{
//Flash_ptr2=(int *) 0x1040;
//Flash_ptr2=Flash_ptr1;
state = *Flash_ptr1;
return state;
}
Write function is writing that particular value to 0x1000 location i have checked in memory browser in run mode.and even it is reading properly but that read value is lost when the power is off.or my entire program and understanding is faulty , which am unable to find it out.
Thank you in advance