I have to write 300 Byte of data in flash.
I write this simple routine, but i think that there is ana error because this routine stops my f2272.
can anyone please help me?
thank'you very much.
This is the function:
void
write_FlashByte(char value, uint8 index)
{
volatile
char
CAL_DATA[FLASH_MEM_DIM];
char
*Flash_ptr; // Flash pointer
uint16 i;
FCTL2 = FWKEY + FSSEL0 + FN1;
// MCLK/3 for Flash Timing Generator
Flash_ptr =0x0fe00
; // Initialize Flash pointer
for (i = 0; i < FLASH_MEM_DIM; i++) //save old data in memory
{
CAL_DATA[i] = *Flash_ptr++;
}
Flash_ptr = (
char*)0x0fe00;// 0xfd00 ; // Initialize Flash pointer
FCTL3 = FWKEY;
// Clear Lock bit
FCTL1 = FWKEY + ERASE + EEI;
// Set Erase bit, allow interrupts
*Flash_ptr = 0;
// Dummy write to erase Flash seg
FCTL1 = FWKEY + WRT;
// Set WRT bit for write operation
/************************************************************
at this point the f2272 remains blocked
*************************************************************/
for (i = 0; i < ADDR_DATA_MEM; i++) //save old data in memory
{
if(i == index)
*Flash_ptr++ = value;
//write new value to flash
else
*Flash_ptr++ = CAL_DATA[i];
// Write old value to flash
}
FCTL1 = FWKEY;
// Clear WRT bit
FCTL3 = FWKEY + LOCK;
// Set LOCK bit
}
Help me please!
thank'you!