打印
[Cortex-M0技术交流]

I2C向E2PROM写数据出错的问题

[复制链接]
1958|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
PrimoQin|  楼主 | 2013-4-6 18:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 PrimoQin 于 2013-4-6 18:32 编辑

向E2PROM的三个地址连续写入三个数据,第一个地址的数据能成功写入,第二个、第三个数据却不能写入,请问这是什么原因。
单独写一个数据是能正常写入的,为何后面的却写入不了,请高手指点,帮忙找找问题所在.
程序如下:
void I2C_Init(void)
{

/* Reset I2C0 */
  SYS->IPRSTC2.I2C_RST = 1;
  SYS->IPRSTC2.I2C_RST = 0;

SYS->P3_MFP.MFP4_T0_SDA = 0; //P3.4/P3.5 为I2C模式
SYS->P3_MFP.MFP5_T1_SCL = 0;
SYS->P3_MFP.ALT4_T0_SDA = 1;
SYS->P3_MFP.ALT5_T1_SCL = 1;

SYSCLK->APBCLK.I2C_EN = 1;
I2C->I2CLK = 40;
I2C->I2CON.ENS1 = 1;
}

void I2C_Open(void)
{
  SYSCLK->APBCLK.I2C_EN = 1;
  I2C->I2CON.ENS1 = 1;
}

void I2C_Close(void)
{
SYSCLK->APBCLK.I2C_EN = 0;
I2C->I2CON.ENS1 = 0;
}

void I2C_SET_CONTROL_BIT(uint8_t STA,uint8_t STO,uint8_t SI,uint8_t AA)
{
I2C->I2CON.STA = STA;
I2C->I2CON.STO = STO;
I2C->I2CON.SI = SI;  
I2C->I2CON.AA = AA;
}

void 24C64_Write(uint8_t DeviceAddr,uint16_t REG_Address,uint8_t DATA)
{
I2C_Open();

I2C_SET_CONTROL_BIT(1,0,0,0); //set STA
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = DeviceAddr;
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = (REG_Address>>8);
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = REG_Address;
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = DATA;
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C_SET_CONTROL_BIT(0,1,1,0);
I2C_Close();
}
uint8_t 24C64_Read(uint8_t DeviceAddr,uint32_t REG_Address)
{
uint8_t TEMP;
I2C_Open();

I2C_SET_CONTROL_BIT(1,0,0,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = DeviceAddr;
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = (REG_Address>>8) & 0xff;
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = REG_Address & 0xff;
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C_SET_CONTROL_BIT(1,0,1,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = DeviceAddr+0x01;
I2C_SET_CONTROL_BIT(0,0,1,0);
while(I2C->I2CON.SI == 0);

I2C->I2CDAT = 0x00;
I2C_SET_CONTROL_BIT(0,0,1,1);
while(I2C->I2CON.SI == 0);
TEMP = I2C->I2CDAT;

I2C_SET_CONTROL_BIT(0,1,1,0);
I2C_Close();
return(TEMP);
}
主程序:
main()
{
  uint8_t DATA_temp;
    UNLOCKREG();
  //SelectClk_12M();
  SYS_Init();
   LOCKREG();
I2C_Init();
  DATA_temp  = 0x71;
  FM24C64_Write(0xA0,0x0000,DATA_temp);
  DATA_temp  = 0x78;
  FM24C64_Write(0xA0,0x0007,DATA_temp);
  DATA_temp  = 0x79;
  FM24C64_Write(0xA0,0x0010,DATA_temp);
while(1)
{
   DATA_temp = FM24C64_Read(0xA0,0x0000);
   DISPLAY(DATA_temp);//显示读出的数据
   DATA_temp = FM24C64_Read(0xA0,0x0007);
  DISPLAY(DATA_temp);
   DATA_temp = FM24C64_Read(0xA0,0x0010);
   DISPLAY(DATA_temp);
   delay(80000);
}

}

地址为0x0000的数据能正常写入,之后的0x0007/0x0010两个地址的数据却不能写入,请问这是什么原因。



相关帖子

沙发
PrimoQin|  楼主 | 2013-4-7 22:11 | 只看该作者
各位大神,有时间的话,帮忙看看吧,急。。。

使用特权

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

本版积分规则

2

主题

4

帖子

0

粉丝