用的是Dspic33ep512GM310,把一些参数写在flash里面保存,写的地址是0x52400,在擦除和写之后,Usart中断就停止工作了,是不是我的擦除函数和写函数有问题,熟悉的帮我看下
uint8 PageErase( uint32 flashAddress )
{
NVMADR = ( flashAddress & 0xffff );
NVMADRU = ( (flashAddress >> 16) & 0xffff );
while(NVMCONbits.WR);
NVMCON = 0x4003;
__builtin_disi( 6);
__builtin_write_NVM();
Nop();
Nop();
while(NVMCONbits.WR);
Nop();
Nop();
NVMCONbits.WREN=0;
Nop();
if( (NVMCONbits.WRERR == 1) || (NVMCONbits.URERR == 1) )
{
return ( WRERR_OR_UERR_ERROR );
}
else
{
return ( NO_ERROR );
}
}
uint8 WordWrite( uint32 flashAddress, uint16 ramBuffer1,uint16 ramBuffer2)
{
// Set up the NVMADR registers to the starting address of the page
NVMADR = ( flashAddress & 0xFFFF );
NVMADRU = ( (flashAddress >> 16) & 0xFFFF );
NVMCON = 0x4001;
TBLPAG=0xfa;
__builtin_tblwtl(0x0000,ramBuffer1);//(( flashAddress & 0xFFFF ),ramBuffer);
__builtin_tblwth(0x0001,0x00);//(( flashAddress & 0xFFFF )+1,0x00);
__builtin_tblwtl(0x0002,ramBuffer2);
__builtin_tblwth(0x0003,0x00);
__builtin_disi( 6);
__builtin_write_NVM();
if( (NVMCONbits.WRERR == 1) || (NVMCONbits.URERR == 1) )
{
return ( WRERR_OR_UERR_ERROR );
}
else
{
return ( NO_ERROR );
}
}
此帖出自
小平头技术问答
一周热门 更多>