Other Parts Discussed in Thread: MSP430G2553
hi,
i am using the following code for my project. In this test code i have given 10 characters in an array "Wdata"
i am trying to write this data in Flash.
after writing has done. i am reading the data from same memory. whats the problem is after reading the data in "Rdata[10]" is
{ '7', '.' , '2' , '.' , '0' , '.' , '4' , '.' , '2' , '.' };
can anyone tell me how to use the flash write correctly..!
here the code is..
#include <msp430.h>
char Rdata[10];
char Wdata[10]={'7','2','0','4','2','8','6','2','2','8'};
// Function prototypes
void read (void);
void write (void);
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz
DCOCTL = CALDCO_8MHZ;
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
write();
read();
while(1); //debugging
}
void read()
{
char *Flash_ptr;
unsigned int i;
Flash_ptr = (char *) 0x1040;
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment D
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<10; i++)
{
Rdata[i++] = *Flash_ptr++;
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void write ()
{
char *Flash_ptr; // Flash pointer
unsigned int i;
Flash_ptr = (char *) 0x1040; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<10; i++)
{
*Flash_ptr++ = Wdata[i++]; // Write value to flash
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
thank you!