This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 - Internal Flash Memory Read/Write Problem (MSP430G2955)

Other Parts Discussed in Thread: MSP430G2955

Memory Write :

_DINT(); // Disable Interrupt 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 *mem_address = 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 FCTL2 = FWKEY + FSSEL_1 + FN3; // Clk = SMCLK/4 FCTL3 = FWKEY; // Clear Lock bit FCTL1 = FWKEY + WRT; // Set WRT bit for write operation mem_address = (char *) 0x0E00A; *mem_address = 55; mem_address = (char *) 0x0E00B; *mem_address = temp; // copy value to flash FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit _EINT(); // Enable Interrupt

Hello,

I am working on a project, which uses the internal memory storage of the Microcontroller - MSP430G2955. The Main purpose is to store two variable into memory locations. So that If the power failure occurs, the previous status can be retrieved from the memory. For that 55D(37H) is stored in the memory location 0x0E00A & temp variable is stored in memory location 0x0E00B.

The problem is, When I use debugger, It works well but when I use external power supply, it does not work. 

For the said problem one can think to review the power supply section, but with the same power supply section and with the same program code the other project works well. 

So please suggest me the possible solutions for the said problem.

The memory read program is also shown here. 

main()
{
        ......
        ......
	mem_address = (char *) 0x0E00A;
	new_var = eeprom_read();
	mem_address = (char *) 0x0E00B;
	temp_var = eeprom_read();
        ......
        ......
}


unsigned char eeprom_read(void)
{
	unsigned char mem_read;
	FCTL2 = FWKEY;
	FCTL3 = FWKEY;
	FCTL1 = FWKEY;
	mem_read = *mem_address;
	return mem_read;
}

  • For reading memory, you don't need to touch the flash controller at all. Just read it. Flash is read exactly the same way as RAM. The only difference is while writing. So likely your writing function is buggy.

    You can simply do
    new_var = *(char*)0xE00A;
    without any function call.
    you can even define a
    char * const new_var_ptr = 0xE00A;
    and later use
    new_var = *new_var_ptr;
    or simply use (*new_var_ptr) directly.

    BTW: you should pass mem_address as value to a function rather than setting it globally. Else you can easily lose clear view of what the function will do on more complex projects.

**Attention** This is a public forum