在看DSP28335开发板提供的EEPROM程序的时候,有些地方看不懂,望大神指教。EEPROM用的是AT24C01。
例程里的WriteData(dat,0x60,8)和ReadData(dat,0x60,8)里的0x60在函数里是什么意思啊?#include"DSP2833x_Devi...
例程里的WriteData(dat,0x60,8)和ReadData(dat,0x60,8)里的0x60在函数里是什么意思啊?
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
void InitI2C(void);
Uint16 ReadData(Uint16 *RamAddr, Uint16 RomAddress, Uint16 number);
Uint16 WriteData(Uint16 *Wdata, Uint16 RomAddress, Uint16 number);
Uint16 I2C_xrdy();
Uint16 I2C_rrdy();
Uint16 i;
Uint16 dat1[8]={0,0,0,0,0,0,0,0};
Uint16 dat[]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
void main(void)
{
InitSysCtrl();
InitXintf16Gpio(); //zq
InitI2CGpio();
InitI2C();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
WriteData(dat,0x60,8);
DELAY_US(10000);
ReadData(dat1,0x60,8);
for(; ;)
{
}
}
Uint16 WriteData(Uint16 *Wdata, Uint16 RomAddress, Uint16 number)
{
Uint16 i;
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT = number + 1;
I2caRegs.I2CDXR = RomAddress;
I2caRegs.I2CMDR.all = 0x6E20;
for (i=0; i<number; i++)
{
while(!I2C_xrdy());
I2caRegs.I2CDXR = *Wdata;
Wdata++;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
}
return I2C_SUCCESS;
}
Uint16 ReadData(Uint16 *RamAddr, Uint16 RomAddress, Uint16 number)
{
Uint16 i,Temp;
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT = 1;
I2caRegs.I2CDXR = RomAddress;
I2caRegs.I2CMDR.all = 0x6620;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
DELAY_US(50);
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT = number;
I2caRegs.I2CMDR.all = 0x6C20;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
for(i=0;i<number;i++)
{
while(!I2C_rrdy());
Temp = I2caRegs.I2CDRR;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
*RamAddr = Temp;
RamAddr++;
}
return I2C_SUCCESS;
}
Uint16 I2C_xrdy()
{
Uint16 t;
t = I2caRegs.I2CSTR.bit.XRDY;
return t;
}
Uint16 I2C_rrdy()
{
Uint16 t;
t = I2caRegs.I2CSTR.bit.RRDY;
return t;
} 展开
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
void InitI2C(void);
Uint16 ReadData(Uint16 *RamAddr, Uint16 RomAddress, Uint16 number);
Uint16 WriteData(Uint16 *Wdata, Uint16 RomAddress, Uint16 number);
Uint16 I2C_xrdy();
Uint16 I2C_rrdy();
Uint16 i;
Uint16 dat1[8]={0,0,0,0,0,0,0,0};
Uint16 dat[]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
void main(void)
{
InitSysCtrl();
InitXintf16Gpio(); //zq
InitI2CGpio();
InitI2C();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
WriteData(dat,0x60,8);
DELAY_US(10000);
ReadData(dat1,0x60,8);
for(; ;)
{
}
}
Uint16 WriteData(Uint16 *Wdata, Uint16 RomAddress, Uint16 number)
{
Uint16 i;
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT = number + 1;
I2caRegs.I2CDXR = RomAddress;
I2caRegs.I2CMDR.all = 0x6E20;
for (i=0; i<number; i++)
{
while(!I2C_xrdy());
I2caRegs.I2CDXR = *Wdata;
Wdata++;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
}
return I2C_SUCCESS;
}
Uint16 ReadData(Uint16 *RamAddr, Uint16 RomAddress, Uint16 number)
{
Uint16 i,Temp;
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT = 1;
I2caRegs.I2CDXR = RomAddress;
I2caRegs.I2CMDR.all = 0x6620;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
DELAY_US(50);
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT = number;
I2caRegs.I2CMDR.all = 0x6C20;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
for(i=0;i<number;i++)
{
while(!I2C_rrdy());
Temp = I2caRegs.I2CDRR;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
*RamAddr = Temp;
RamAddr++;
}
return I2C_SUCCESS;
}
Uint16 I2C_xrdy()
{
Uint16 t;
t = I2caRegs.I2CSTR.bit.XRDY;
return t;
}
Uint16 I2C_rrdy()
{
Uint16 t;
t = I2caRegs.I2CSTR.bit.RRDY;
return t;
} 展开
3个回答
展开全部
Uint16 WriteData(Uint16 *Wdata, Uint16 RomAddress, Uint16 number)
函数原型已经很明显了,那是地址。
函数原型已经很明显了,那是地址。
追问
如果你说的地址是器件地址的话,我查了,AT24C01的器件地址是0xA0,也不是0x60啊
追答
不是器件地址,是要保存的地址。24C01、02、04都是IIC协议的东西。但总体来说是满足单片机系列的东西。要操作的数据时直接寻址的。也就是说读或者写都是直接从芯片0X XX地址直接开始
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
估计已经晚了,但还是想说……那个0x60是写数据到e2prom里的地址……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
应该是你 eeprom的 I2c地址,这个是硬件决定的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询