Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 22223

CCS/MSP430G2553: flash value not saved after restart

$
0
0

Part Number:MSP430G2553

Tool/software: Code Composer Studio

Hi everybody,

I have the following code:

#include <msp430g2553.h>

#define END_OF_FLASH 0x0FFFF

void WriteToFlash(long* Flashptr, long val);
void ReadFromFlash(long* address, long* val);

int main(void) {
	WDTCTL = WDTPW + WDTHOLD;
	BCSCTL1 = CALBC1_1MHZ;                    // Set DCO to 1MHz
	DCOCTL = CALDCO_1MHZ;
	FCTL2 = FWKEY + FSSEL0 + FN1;

	WriteToFlash((long *) 0xFFF0, 1234567);
	long val;
	ReadFromFlash((long *) 0xFFF0, &val);
	return 0;
}


void WriteToFlash(long* address, long val)
{
	long* flash_ptr;
	flash_ptr = address;              // Initialize Flash pointer
	FCTL1 = FWKEY + ERASE;                    // Set Erase bit
	FCTL3 = FWKEY;                            // Clear Lock bit
	*flash_ptr = 0;
	FCTL1 = FWKEY + WRT;
	*flash_ptr = val;
	FCTL1 = FWKEY;                            // Clear WRT bit
	FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}

void ReadFromFlash(long* address, long* val)
{
	long* flash_ptr;
	flash_ptr = address;
	*val = *flash_ptr;
}

This insert 1234567 to the flash and i can read it this code works fine, but when i comment the WriteToFlash and try to run it again i expect to read the same value, but the value is wrong.

what am i missing?

thank you for your help 


Viewing all articles
Browse latest Browse all 22223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>