Hi, In the code below, I am trying to erase a flash page in conjuction with a UART interrupt. By them selves, the interrupt and flash erase work fine, but when I put them together, the flash erase has no effect. Would anyone have any idea how the UART interrupt is affecting my flash erase. Thanks. #include "c8051f060.h" // SFR declarations // ------------------- void flash_erase(int startpage, int npages) { char xdata* data pagePointer = 0; / EA = 0; // temporary disable interrupts FLSCL |= 0x01; // Enable FLASH R/WR via software PSCTL = 0x03; // MOVX erases FLASH pagePointer = (char xdata*)(startpage * 512); *pagePointer = 0; // initiate the erase PSCTL = 0x00; FLSCL |= 0x01; // Disable FLASH R/WR via software } // ---------------------- void UART1_ISR (void) interrupt 20 { if (RI1) { EA = 0; flash_erase(0x1F, 1); RI1 = 0; //clears receive flag } } // --------------- int main() { WDTCN = 0xDE; //disable WDT WDTCN = 0xAD; SFRPAGE = UART1_PAGE; SCON1 = 0x50; // Receive enabled EA = 1; // global interrupt enable EIE2 |= 0x40; // Enable UART1 ISR RI1 = 1; //trigger UART1 interrupt return 0; } //-----end main
Here is latest code with suggested changes. I have a break point in the ISR as shown in the code at //#### BREAK POINT HERE ##### RI1 = 0; At that break point, the code space for address 0x1f * 0x200 = 0x3E00 remains unchanged, (i.e. page not set to all 0xFF.) I think that what happens after that with main and returns is probably not relevant. #include "c8051f060.h" void flash_erase(int startpage, int npages) { char xdata* data pagePointer = 0; FLSCL |= 0x01; // Enable FLASH R/WR PSCTL = 0x03; // MOVX erases FLASH pagePointer = (char xdata*)(startpage * 512); *pagePointer = 0; // initiate erase PSCTL = 0x00; FLSCL |= 0x01; // Disable FLASH R/WR } void UART1_ISR (void) interrupt 20 { if (RI1) { EA = 0; RI1 = 0; flash_erase(0x1F, 1); //#### BREAK POINT HERE ##### RI1 = 0; } } void main(void) { WDTCN = 0xDE; //disable WDT WDTCN = 0xAD; SFRPAGE = UART1_PAGE; SCON1 = 0x50; // Receive enabled EA = 1; // global interrupt enable EIE2 |= 0x40; // Enable UART1 ISR RI1 = 1; //trigger UART1 interrupt }