完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试图删除和重写程序闪存的一部分在我的DSPIC33 EP256GP504。我没有建设xx16功能读取闪存,我得到了我所期望的。但是写和擦除函数似乎不起作用。我已经通过了数据手册、Flash编程参考手册、编译器手册等,所有这些都应该起作用,但没有发生任何事情。对于擦除,我已经验证了NVMADR和NVMADRU包含了一个扇区(1024)边界上要擦除的地址。我将NMVCON设置为0x400,它设置了允许位和扇区擦除模式。当我调用Sy-BuuthTynRealEngnVm时,扇区仍然是完整的(预期所有的0xFF)和NVMCON状态位都是清晰的,表明擦除是成功的,而不是写的。除了写入,我首先使用锁存器,使用0x400 1命令。生成的代码与构建函数所记录的内容不太匹配。特别是,BSET NVMCON,α15实际上表现为BSET 0x729,γ7。NVMCON在地址0x728,所以ITHINKthis应该做同样的事情,但我不确定BSET是否需要一个字对齐,因为它是一个16位指令。如果是这样,那么这是一个编译器错误,如果不是,我更困惑为什么它不起作用。不知怎的,我想我错过了一些小细节,但它逃避我-帮助!以下是我的项目中的一些代码片段:用于擦除:TBLPAG=NVPAGE;NVMADRU=NVPAGE;NVMADR=I;//设置低16位地址去擦除(1024扇区边界)NVMCON=0x400 3;//设置扇区擦除模式和写Enable CypTraceGualDeabable();用于写(发生在循环设置C和I中):TBLPAG=NVPAGE;μ-Bug TynIn TBLWTL(C,FLASH .O.X);/ /将16位值写入到低WorddSuxtiNIN TBLWTH(C,I);/ /写入索引值到高WorddBug构建TBLWTL(C++ 2,Flash .O.x[i+1]);/ /写入16位值到低WorddBuiTynIn TBLWTH(C + 2,I + 1);/ /写索引值高WordDNVMADRU= NVPAGE;NVMADR=C;/ /指向WordSNVMCON=0x400 1;!
以上来自于百度翻译 以下为原文 I'm trying to erase and rewrite a part of Program flash memory in my dsPic33EP256GP504. I have no trouble with the builtin XC16 functions to read flash, and I get exactly what I expect. But the write and erase functions do not seem to work. I've been through the data book, the flash programming reference manual, the compiler manual, etc., and it all should function but nothing happens. For erasing I've verified that the NVMADR and NVMADRU contain the address I want to erase, on a sector (1024) boundary. I set the NMVCON to 0x4003, which sets the enable bit and the sector erase mode. When I call the __builtin_write_NVM, the sector is still intact (expecting all 0xff) and the NVMCON status bits are all clear indicating that the erase was successful when it was not. For writing I do the same, except that I set the latches first and use the 0x4001 command. What I notice is that the generated code does not quite match what is documented for the builtin function. In particular, the BSET _NVMCON, #15 actually appears as BSET 0x729, #7. NVMCON is at address 0x728, so I THINK this should do the same thing, but I'm not sure if the BSET requires a word alignment since it's a 16 bit instruction. If it does, then this is a compiler bug, if not I'm even more confused why it doesn't work. Somehow I think I'm missing some minor detail, but it's eluding me - HELP! Here's some code snippets from my project: For erasing: TBLPAG = NVPAGE; NVMADRU = NVPAGE; NVMADR = i; //Set low 16 bits of address to erase (1024 sector boundry) NVMCON = 0x4003; //Set sector erase mode and write enable INTERRUPT_GlobalDisable(); __builtin_write_NVM(); //Erase sector now! INTERRUPT_GlobalEnable(); For Writing (occurs inside a loop setting c and i): TBLPAG = NVPAGE; __builtin_tblwtl(c, flash.o.x); //Write 16 bit value to low word __builtin_tblwth(c, i); //Write index value to high word __builtin_tblwtl(c+2, flash.o.x[i+1]); //Write 16 bit value to low word __builtin_tblwth(c+2, i+1); //Write index value to high word NVMADRU = NVPAGE; NVMADR = c; //Point to lower of the words NVMCON = 0x4001; //Set double word program command INTERRUPT_GlobalDisable(); __builtin_write_NVM(); //Write words now! INTERRUPT_GlobalEnable(); |
|
相关推荐
2个回答
|
|
我为Flash写和读操作做了这个代码,但它根本不起作用。所以,纠正我错误的地方。Vo.FyWrreWe(){int偏移,i;TBLPAG=0xFA;偏移=0;(i=0;i & lt;} NVMADRU=α-Bug TynIn TBLPAGE(和;MyDATALNFLASH);Office=Y-BuuthTiNeTBLOPENCE(ANP;MyDATALNFLASH);NVMADR=(偏移量和0xF800);NVMCON=0x400 2;/ /禁用中断A*Bug(6);//写入密钥序列并启动编程序列
以上来自于百度翻译 以下为原文 i did this code for flash write and read operation but it wont work at all. so,correct me where i got at wrong. void F_write() { int offset,i; TBLPAG = 0xFA; offset = 0; for(i=0;i<_FLASH_ROW*2;i++) { __builtin_tblwtl(offset,RamData2Write[i++]); __builtin_tblwth(offset,RamData2Write); offset += 2; } NVMADRU = __builtin_tblpage(&MyDatalnFlash); offset = __builtin_tbloffset(&MyDatalnFlash); NVMADR=(offset&0xF800); NVMCON = 0x4002; //Disable interrupts __builtin_disi(6); //Write the KEY sequence and Start the programming sequence __builtin_write_NVM(); } |
|
|
|
A)如果你没有指定你的PIC(和编译器),没人能告诉你你的代码是否正确。B)“不起作用”让我们猜测到目前为止你测试了什么,你是如何测试的,你所期望的,你得到的。C)你知道你也必须在某个点上擦除吗?D)请不要劫持一个旧线程,创建你自己的线程。
以上来自于百度翻译 以下为原文 a) If you do not specify your PIC (and compiler) nobody can tell whether your code is ok or not. b) "does not work" leaves us to guess what you have tested so far,- how you test, what you expect, what you get. c) did you understand that you also have to ERASE at some point ? d) Please don't hijack an old thread, create your own. |
|
|
|
只有小组成员才能发言,加入小组>>
5163 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
732浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
505浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 19:33 , Processed in 1.207274 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号