Hello, first post and looking for insight. I'm trying to store four bytes of data in the Info Flash for retention between power cycles. This is an MSP430G2231 chip and I'm using the MSPGCC compiler.
I have no problem storing three of the four bytes, but the first byte never writes. When I look at 0x1000 with the debugger it reads:
1000: ff 02 03 04 ff ff ff ff ff ff ff ff ff ff ff ff |................|
Here's my code:
#include <io.h> unsigned char code1 = 1; unsigned char code2 = 2; unsigned char code3 = 3; unsigned char code4 = 4; // Function prototypes void store_code(); void clear_flash(void); int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) { while(1); // If calibration constants erased // do not load, trap CPU!! } BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; FCTL2 = FWKEY + FSSEL_1 + FN2; // MCLK/3 for Flash Timing Generator clear_flash(); store_code(); while(1); // Repeat forever } void clear_flash(void) { int *Flash_ptr; Flash_ptr = (int *)0x1000; //Point to Info Flash segment D FCTL3 = FWKEY; // Clear Lock bit FCTL1 = FWKEY + ERASE; // Set Erase bit *Flash_ptr = 0; // Dummy write to erase Flash segment D FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit } void store_code(void) { char *Flash_ptr; Flash_ptr = (char *) 0x1000; //Point to Info Flash segment D FCTL3 = FWKEY; // Clear Lock bit FCTL1 = FWKEY + WRT; // Set WRT bit for write operation *Flash_ptr++ = code1; *Flash_ptr++ = code2; *Flash_ptr++ = code3; *Flash_ptr++ = code4; FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit }