Hi all:
I'm trying to erase/write data to MSP4305529 (launch pad) by CCSv6.0.
And then I want to read out the data for each address in 4 main blocks.
For each address, need to record the data to txt file.
However, I think I could correctly operate flash memory, but there is not any output in the txt file (0KB).
Here under is my code, is there anyone could answer my question? Many thanks!
#include <msp430.h>
#include <stdio.h>
// Function prototypes
void erase_Seg(void);
void wrt_Bank1(void);
void wrt_to_txt(void);
char value; // 8-bit value to write to Bank 1
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop WDT
value = 0;
erase_Seg();
wrt_Bank1();
wrt_to_txt();
while(1){
__no_operation();
}
}
//------------------------------------------------------------------------------
// Erases Memory Bank 1
//------------------------------------------------------------------------------
void erase_Seg(void)
{
char *Flash_ptr = (char *)0xFF80; // Initialize Flash pointer
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+ERASE+MERAS; // Set All Erase bit
_DINT();
*Flash_ptr = 0; // Dummy erase byte
while(FCTL3 & BUSY);
_EINT();
FCTL1 = FWKEY;
FCTL3 = FWKEY+LOCK; // Set LOCK bit
}
//------------------------------------------------------------------------------
// Writes incremented Value to Bank 1
//------------------------------------------------------------------------------
void wrt_Bank1(void)
{
unsigned int i;
char *Flash_ptr = (char *)0xFF80; // Initialize Flash pointer
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+WRT; // Set WRT bit for write operation
_DINT();
for(i = 0; i < 128000; i++)
{
*Flash_ptr++ = value; // Write a word to flash
}
while(FCTL3 & BUSY);
_EINT();
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY+LOCK; // Set LOCK bit
}
void wrt_to_txt(void)
{
unsigned int i;
char tmpVal;
char *Flash_ptr = (char *)0xFF80;
FILE *fp;
fp = fopen("d:\\data2.txt","w");
for(i = 0; i < 128000; i++)
{
tmpVal = *Flash_ptr++; // Read a word to flash
fprintf(fp,"%x\n",&tmpVal);
}
fclose(fp);
}