打印

Dspic33EP512*写flash的问题

[复制链接]
1502|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
elephant00|  楼主 | 2021-8-19 10:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
用的是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 );
    }

}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

919

主题

2501

帖子

4

粉丝