Wonder if someone can help me. I am fairly new to C coding on these chips, but have had a lot of success through trial and error and reading a lot of blogs, forum posts etc.
Most of the code below is borrowed from other peoples articles about erasing/writing and reading from the MSP430 flash memory system.
#include <msp430.h> //************************************************************************* // Erase Information Flash //************************************************************************* void flash_erase(int *addr) { __disable_interrupt(); // Disable interrupts. This is important, otherwise, // a flash operation in progress while interrupt may // crash the system. while(BUSY & FCTL3); // Check if Flash being used FCTL2 = FWKEY + FSSEL_1 + FN3; // Clk = SMCLK/4 FCTL1 = FWKEY + ERASE; // Set Erase bit FCTL3 = FWKEY; // Clear Lock bit *addr = 0; // Dummy write to erase Flash segment while(BUSY & FCTL3); // Check if Flash being used FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit __enable_interrupt(); } //************************************************************************* // Read stored Information flash //************************************************************************* void flash_write(int *addr) { __disable_interrupt(); FCTL2 = FWKEY + FSSEL_1 + FN0; // Clk = SMCLK/4 FCTL3 = FWKEY; // Clear Lock bit FCTL1 = FWKEY + WRT; // Set WRT bit for write operation *addr++ = 50; // copy value to flash *addr++ = 51; // copy value to flash FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit while(BUSY & FCTL3); __enable_interrupt(); } /* * main.c */ int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer int *addr = (int *)0x0E000 ; // Address of the flash memory segment starting int *addr2 = (int *)0x0E000 ; // Address of the flash memory segment starting int i; int j; flash_erase(addr); flash_write(addr); i = *addr2; j = *addr2; return 0; }
The code above is just test code to see if I can write to memory and then read it back afterwards.
If I run this code it does work, using the CCS Memory dump tool I can see the values of 50 and 51 in the right locations of flash memory. However, if I try to put a breakpoint at either line 63 or 64, it actually won't hit debug until the return 0; statement that follows, and there is nothing in variables I or J.
I am guessing I am doing something stupid - but I really can't tell what it is.
Any idea? (thanks in advance!)