我正在使用C8051F340并将一些随机数保存到我的闪存中,我现在遇到的问题是如果我先擦除然后写入然后读取它,值是正确的。但是,如果我只使用读取函数,它只会给我255正确的值。 这是代码。
buf[0] = 1;
buf[1] = 1;
buf[2] = 1;
buf[3] = 1;
buf[4] = 1;
buf[5] = 0;
buf[6] = 1;
buf[7] = 1;
buf[8] = 1;
buf[9] = 1;
buf[10] = 1;
buf[11] = 1;
buf[12] = 1;
buf[13] = 1;
buf[14] = 1;
buf[15] = 1;
FLASH_PageErase (0x3200);
for(i=0;i<16;i++)
{
FLASH_ByteWrite(0x3200+i, buf[i]);
read_buf[i] = FLASH_ByteRead (0x3200+i);
}
在那些代码之后,我发现我的read_buf [i]是:1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1
但如果我只做读功能:
buf[0] = 1;
buf[1] = 1;
buf[2] = 1;
buf[3] = 1;
buf[4] = 1;
buf[5] = 0;
buf[6] = 1;
buf[7] = 1;
buf[8] = 1;
buf[9] = 1;
buf[10] = 1;
buf[11] = 1;
buf[12] = 1;
buf[13] = 1;
buf[14] = 1;
buf[15] = 1;
for(i=0;i<16;i++)
{
read_buf[i] = FLASH_ByteRead (0x3200+i);
}
我的read_buf [i]的结果是:255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255