Hello All.
I have some strange behaviour when trying to write byte in Flash Memory.
FlashWriteByte: copy (DataLen) Byte from DataPtr (RAM Memory) to Flashptr (Flash Memory)
Here is the code
--------------------------------------------------------------------------------------------------------------------------------
void FlashWriteByte(unsigned char *FlashPtr, unsigned int DataLen, unsigned char *DataPtr)
{
unsigned int ByteQty;
WDTCTL = WDTPW + WDTHOLD;
_DINT();
FCTL3=FWKEY; //Lock=0
FCTL1=FWKEY+WRT; //WRT=1
for(ByteQty=0; ByteQty<DataLen; ByteQty++)
{
while((FCTL3&0x0008)==0) ; // flash memory write is busy
*FlashPtr++=*DataPtr++; // Program flash byte
}
FCTL1=FWKEY; //WRT=0
FCTL3=FWKEY+LOCK; //Lock=1
_EINT();
}
--------------------------------------------------------------------------------------------------------------------------------
The problem lies here : *Flashptr++=*Dataptr++
By replacing this line with the 3 lines below:
*Flashptr=*Dataptr;
Flashptr++;
Dataptr++;
It works. I have no problem with IAR compiler.