本帖最后由 ZSR20181017 于 2018-12-1 19:08 编辑
下面这个读写测试历程里面,有个地方没搞明白,就是写函数EE_WriteByte(write_buf, 16, 50),写的起始地址是16,然后我读函数EE_ReadByte(read_buf, 16, 50)里面的起始地址应该也是16才对啊,可是并不是我想的那样;
经过几轮测试发现,读函数EE_ReadByte(read_buf, 0, 50)里面的起始地址改为0才能正确读出;
串口输出截图:
EEPROM软件模拟测试
写eeprom成功!
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
46 47 48 49
读eeprom成功,数据如下:
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
45 46 47 48 49
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49
eeprom读写测试成功
uint8_t ee_Test(void)
{
uint16_t i;
uint8_t write_buf[EEPROM_SIZE];//EEPROM_SIZE
uint8_t read_buf[EEPROM_SIZE];
/*-----------------------------------------------------------------------------------*/
if (EE_Check_OK() == 0)
{
/* 没有检测到EEPROM */
printf("没有检测到串行EEPROM!\r\n");
return 0;
}
/*------------------------------------------------------------------------------------*/
/* 填充测试缓冲区 */
for (i = 0; i < 50; i++)
{
write_buf = i;
}
/*------------------------------------------------------------------------------------*/
if (EE_WriteByte(write_buf, 16, 50) == 0)
{
printf(&quot;写eeprom出错!\r\n&quot;);
return 0;
}
else
{
printf(&quot;写eeprom成功!\r\n&quot;);
for(i=0;i<50;i++)
{
printf(&quot; %02d&quot;, write_buf);
}
}
/*写完之后需要适当的延时再去读,不然会出错*/
EE_Delay(0x0FFFFF);
/*-----------------------------------------------------------------------------------*/
if (EE_ReadByte(read_buf, 0, 50) == 0)
{
printf(&quot;读eeprom出错!\r\n&quot;);
return 0;
}
else
{
printf(&quot;读eeprom成功,数据如下:\r\n&quot;);
for(i=0;i<50;i++)
{
printf(&quot;%02d &quot;, read_buf);
}
printf(&quot;\r\n&quot;);
//printf(&quot; %02X&quot;, read_buf);
}
/*-----------------------------------------------------------------------------------*/
for (i = 0; i < 50; i++)
{
if(read_buf != write_buf)
{
//printf(&quot;0x%02X &quot;, read_buf);
printf(&quot;错误:EEPROM读出与写入的数据不一致&quot;);
return 0;
}
printf(&quot; %02d&quot;, read_buf);
if ((i & 15) == 15)
{
printf(&quot;\r\n&quot;);
}
}
printf(&quot;eeprom读写测试成功\r\n&quot;);
return 1;
} |