I am having problems writing to memory after erasing a segment. So far I have only developed a simple test code. I erase the segment starting with address 0xC400. Then I write a test byte to that address. Also I write a test byte to address 0xC600. When I run the code and read it back out of the microcontroller, address 0xC400 is blank, but the test byte is there at 0xC600. I have also run tests where I did an erase of memory starting with address 0XC600. When I read it back then the test byte at 0xC400 is there, but the one at 0xC600 was not. I also ran it erasing the segment starting at 0XC000. This of course erased all of the program, but it proved my erase code works. So it appears my code will erase a segment and can program a byte(or word, I have done it that way as well), but can not write to a segment that it erased. Any suggestions where I may have gone wrong?
int main(void)
{
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
char *Flash_ptr = (char *)0xC400;
char *data_ptr = (char *)0xC600;
__bic_SR_register (GIE); //disable interrupts
WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer
P3DIR = 0x08; //setup output for LED
P3OUT = 0x00;
FCTL3 = FWKEY;
FCTL1 = FWKEY + ERASE;
*Flash_ptr = 0; // erase Flash segment
while(FCTL3 & BUSY);
FCTL1 = FWKEY+WRT;
*Flash_ptr = 0xAA;
*data_ptr = 0x55;
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
P3OUT = 0x08; //turn on LED
for (;;) // loop forever
{}
}