打印

EEPROM页写很奇怪的现象

[复制链接]
3137|13
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
MCU:PIC24H228
EEPROM:24LC32A 32bytes/page
我将页地址起始设置为0、32、64、128时,读写正常,其它(32倍数)的时不正常
#if 1
unsigned char ee_test[100];
for(i=0;i<100;i++)
  ee_test[i]=i+10;
EEPROMPageWrite(0,ee_test,PAGE_SIZE);
Delayms(50);
EEPROMPageWrite(0+32,ee_test+32,PAGE_SIZE);
Delayms(50);
EEPROMPageWrite(0+64,ee_test+64,PAGE_SIZE);
Delayms(50);
EEPROMPageWrite(0+96,ee_test+96,4);
Delayms(50);

for(i=0;i<100;i++)
  ee_test[i]=0;
EEPROMRead(0,ee_test,PAGE_SIZE);
for(i=0;i<PAGE_SIZE;i++)
{
  sprintf(debug_str,"read:%d=%d\r\n",i,ee_test[i]);
  DEBUG_PRINTSTR(debug_str);
}
EEPROMRead(0+32,ee_test,PAGE_SIZE);
for(i=0;i<PAGE_SIZE;i++)
{
  sprintf(debug_str,"read32:%d=%d\r\n",i+32,ee_test[i]);
  DEBUG_PRINTSTR(debug_str);
}
EEPROMRead(0+64,ee_test,PAGE_SIZE);
for(i=0;i<PAGE_SIZE;i++)
{
  sprintf(debug_str,"read64:%d=%d\r\n",i+64,ee_test[i]);
  DEBUG_PRINTSTR(debug_str);
}

结果:
read:0=10
read:1=11
read:2=12
read:3=13
read:4=14
read:5=15
read:6=16
read:7=17
read:8=18
read:9=19
read:10=20
read:11=21
read:12=22
read:13=23
read:14=24
read:15=25
read:16=26
read:17=27
read:18=28
read:19=29
read:20=30
read:21=31
read:22=32
read:23=33
read:24=34
read:25=35
read:26=36
read:27=37
read:28=38
read:29=39
read:30=40
read:31=41
read32:32=42
read32:33=43
read32:34=44
read32:35=45
read32:36=46
read32:37=47
read32:38=48
read32:39=49
read32:40=50
read32:41=51
read32:42=52
read32:43=53
read32:44=54
read32:45=55
read32:46=56
read32:47=57
read32:48=58
read32:49=59
read32:50=60
read32:51=61
read32:52=62
read32:53=63
read32:54=64
read32:55=65
read32:56=66
read32:57=67
read32:58=68
read32:59=69
read32:60=70
read32:61=71
read32:62=72
read32:63=73
read64:64=74
read64:65=75
read64:66=76
read64:67=77
read64:68=78
read64:69=79
read64:70=80
read64:71=81
read64:72=82
read64:73=83
read64:74=84
read64:75=85
read64:76=86
read64:77=87
read64:78=88
read64:79=89
read64:80=90
read64:81=91
read64:82=92
read64:83=93
read64:84=94
read64:85=95
read64:86=96
read64:87=97
read64:88=98
read64:89=99
read64:90=100
read64:91=101
read64:92=102
read64:93=103
read64:94=104
read64:95=105

该成这样之后,就不正常了
#if 1
unsigned char ee_test[100];
for(i=0;i<100;i++)
  ee_test[i]=i+10;
EEPROMPageWrite(256,ee_test,PAGE_SIZE);
Delayms(50);
EEPROMPageWrite(256+32,ee_test+32,PAGE_SIZE);
Delayms(50);
EEPROMPageWrite(256+64,ee_test+64,PAGE_SIZE);
Delayms(50);
EEPROMPageWrite(256+96,ee_test+96,4);
Delayms(50);

for(i=0;i<100;i++)
  ee_test[i]=0;
EEPROMRead(256,ee_test,PAGE_SIZE);
for(i=0;i<PAGE_SIZE;i++)
{
  sprintf(debug_str,"read:%d=%d\r\n",i,ee_test[i]);
  DEBUG_PRINTSTR(debug_str);
}
EEPROMRead(256+32,ee_test,PAGE_SIZE);
for(i=0;i<PAGE_SIZE;i++)
{
  sprintf(debug_str,"read32:%d=%d\r\n",i+32,ee_test[i]);
  DEBUG_PRINTSTR(debug_str);
}
EEPROMRead(256+64,ee_test,PAGE_SIZE);
for(i=0;i<PAGE_SIZE;i++)
{
  sprintf(debug_str,"read64:%d=%d\r\n",i+64,ee_test[i]);
  DEBUG_PRINTSTR(debug_str);
}

// sprintf(debug_str,"ee read:%d,%d",ee_test[PAGE_SIZE-2],ee_test[PAGE_SIZE-1]);
// DEBUG_PRINTSTR(debug_str);
#endif

结果:
read:0=10
read:1=11
read:2=12
read:3=13
read:4=14
read:5=15
read:6=16
read:7=17
read:8=18
read:9=19
read:10=20
read:11=21
read:12=22
read:13=23
read:14=24
read:15=25
read:16=26
read:17=27
read:18=28
read:19=29
read:20=30
read:21=31
read:22=32
read:23=33
read:24=34
read:25=35
read:26=36
read:27=37
read:28=38
read:29=39
read:30=40
read:31=73
read32:32=42
read32:33=43
read32:34=44
read32:35=45
read32:36=46
read32:37=47
read32:38=48
read32:39=49
read32:40=50
read32:41=51
read32:42=52
read32:43=53
read32:44=54
read32:45=55
read32:46=56
read32:47=57
read32:48=58
read32:49=59
read32:50=60
read32:51=61
read32:52=62
read32:53=63
read32:54=64
read32:55=65
read32:56=66
read32:57=67
read32:58=68
read32:59=69
read32:60=70
read32:61=71
read32:62=72
read32:63=105
read64:64=74
read64:65=75
read64:66=76
read64:67=77
read64:68=78
read64:69=79
read64:70=80
read64:71=81
read64:72=82
read64:73=83
read64:74=84
read64:75=85
read64:76=86
read64:77=87
read64:78=88
read64:79=89
read64:80=90
read64:81=91
read64:82=92
read64:83=93
read64:84=94
read64:85=95
read64:86=96
read64:87=97
read64:88=98
read64:89=99
read64:90=100
read64:91=101
read64:92=102
read64:93=103
read64:94=104
read64:95=255

希望大家帮忙看看,谢谢!
沙发
Ryanhsiung| | 2012-4-14 18:04 | 只看该作者
EEPROMPageWrite 类型你不会用了8位的吗,这个要16位的

使用特权

评论回复
板凳
NE5532| | 2012-4-15 11:48 | 只看该作者
"我将页地址起始设置为0、32、64、128时,读写正常,其它(32倍数)的时不正常"
64不是32的倍数啊?可见楼主粗心的程度啊……

使用特权

评论回复
评分
参与人数 1威望 +1 收起 理由
yinlb1987 + 1
地板
yinlb1987|  楼主 | 2012-4-15 20:26 | 只看该作者
3# NE5532 地址是用的16位的,明天去公司了上代码。

使用特权

评论回复
5
yinlb1987|  楼主 | 2012-4-15 20:27 | 只看该作者
4# yinlb1987 64不是32的倍数啊?
麻烦细说下,谢谢!

使用特权

评论回复
6
NE5532| | 2012-4-15 20:43 | 只看该作者
你没发现你的话前后矛盾啊,前面说64正常,后面说32的倍数都不正常,那64既然是32的倍数,他为啥正常,楼主早这样去想问题,可能早就找到原因了哈。

使用特权

评论回复
7
yinlb1987|  楼主 | 2012-4-16 08:02 | 只看该作者
6# NE5532
可能您误解我的意思了,我的原文
我将页地址起始设置为0、32、64、128时,读写正常,其它(32倍数)的时不正常
我的意思是 0 32 64 128这几个地址读写正常,其它的就不正常了。
这个是页写的函数
unsigned char EEPROMPageWrite(unsigned int add,unsigned char *buf,unsigned char cnt)
{
unsigned char i=0;
I2CStart();
I2CWriteDat(EEPROM_ADD_WRITE);
if(!I2CCheckAck())
{
  I2CStop();
  return 1;
}

I2CWriteDat((add>>8)&0X0F);
if(!I2CCheckAck())
{
  I2CStop();
  return 2;
}

I2CWriteDat(add%0xff);
if(!I2CCheckAck())
{
  I2CStop();
  return 3;
}
for(i=0;i<cnt;i++)
{
  I2CWriteDat(*buf);
  if(!I2CCheckAck())
  {
   I2CStop();
   return 4;
  }
  buf++;
  
}
I2CStop();
return 0;
}

使用特权

评论回复
8
NE5532| | 2012-4-17 19:56 | 只看该作者
6# NE5532  
可能您误解我的意思了,我的原文
我将页地址起始设置为0、32、64、128时,读写正常,其它(32倍数)的时不正常
我的意思是 0 32 64 128这几个地址读写正常,其它的就不正常了。
这个是页写的函数
unsig ...
yinlb1987 发表于 2012-4-16 08:02


我知道,我是故意误解的,就是要提醒你,你能注意到这个问题,就不至于要求大家帮你才能解决问题了。

使用特权

评论回复
9
lihfos| | 2013-11-1 11:25 | 只看该作者
可能是 24LC32A 只能按页写和按单个字节写 的 原因吧

使用特权

评论回复
10
ayb_ice| | 2013-11-1 15:49 | 只看该作者
其它具体是多少

使用特权

评论回复
11
feixiang549| | 2019-4-27 10:37 | 只看该作者
请问楼主问题怎么解决的?我也遇到一样的问题,求指教。

使用特权

评论回复
12
CoolSilicon| | 2019-4-28 08:53 | 只看该作者
1.首先, 如果你仔细看一下24LC32A的datasheet的话, 上面明确有表示 32-Byte Page Write Buffer, 这个说明, 所以, 你需要遵守芯片page write的要求, 就不要想当然的自创很多个别的用法.
2. 在datasheet的page write章节, 对操作也有明确说明的.
Page write operations are limited to writing
bytes within a single physical page,
regardless of the number of bytes
actually being written. Physical page
boundaries start at addresses that are
integer multiples of the page buffer size (or
‘page size’) and end at addresses that are
integer multiples of [page size – 1]. If a
Page Write command attempts to write
across a physical page boundary, the
result is that the data wraps around to the
beginning of the current page (overwriting
data previously stored there), instead of
being written to the next page as might be
expected. It is therefore necessary for the
application software to prevent page write
operations that would attempt to cross a
page boundary.

使用特权

评论回复
13
CoolSilicon| | 2019-4-28 08:53 | 只看该作者
贴个完整的图

使用特权

评论回复
14
buffered| | 2019-4-28 16:03 | 只看该作者
解决了就好,这个操作的话还是要按照手册来的

使用特权

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

本版积分规则

257

主题

271

帖子

0

粉丝