This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

flash erase with UART interrupt

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

Parents Reply Children
No data