I need to store my boards network ID into nonvolatile memory. I have been using the page_erase() and write_flash_chk():
page_erase(PAGE_START, 0xFF, FDM); write_flash_chk(PAGE_START, NewAddr, FDM);
PAGE_START = 0x0400
//FLASH WRITE CONFIGURATION USEC = 0x0C; //tFWT = 32.5 us MSECH = 0x4E; //MSEC for tFET = 10 ms MSECL = 0x20; // @32 MHz FTCON = 0xFF; //FWR = 0x0F & FER = 0x0F
Erik, On 8052.com Craig suggested I turn of interrupts before doing a page erase. That solved the problem. In the previous veresion I had I wasn't turning off interrupts but it worked, so I am curious to see why! Thank you and everyone else for all your help.
"In the previous veresion I had I wasn't turning off interrupts but it worked, so I am curious to see why!" My Theory: http://www.8052.com/forum/read.phtml?id=100395
Andy, Pure luck is right. I had this board running for months without a problem. I changed one thing and it went down. Thanks for the insight.
"I had this board running for months without a problem" No: you had that board running for months with a problem - you were just lucky enough that the problem never manifested itself! It's that 'Proven Product' Syndrome again: http://www.8052.com/forum/read.phtml?id=78339 Cue: Erik on "Testing" ...
Turning off those interrupts was a cure of symptoms. The problem is that you're erasing a page, which contains not only data, but also code. You can't seriously be surprised that erasing part of the code of your program in mid-operation makes the system somewhat less than reliably. As I said: the solution is to tell the linker not to put any code in that area, period. And even then you may have to turn off interrupts for the time being, depending on whether that EEROM is capable of reading from one page while writing/erasing another.