关于IIC的地址问题
各位兄弟
请问IIC从设备的地址是怎么设置的?不是物理地址吧?是不是芯片自己定义的?
我这有个程序是关于2410通过IIC向AT24C02(EEPROM)中写数据和读取数据的
为什么这里面设置了两个从机地址?:::
void Test_Iic2(void)
{
unsigned int i,j,save_E,save_PE;
static U8 data[256];
Uart_Printf("IIC Test(Polling) using AT24C02\n");
save_E = rGPECON;
save_PE = rGPEUP;
rGPEUP ¦= 0xc000; //Pull-up disable
rGPECON &= ~0xf0000000;
rGPECON ¦= 0xa0000000; //GPE15:IICSDA , GPE14:IICSCL
//Enable ACK, Prescaler IICCLK=PCLK/16, Enable interrupt, Transmit clock value Tx //clock=IICCLK/16
rIICCON = (1 < <7) ¦ (0 < <6) ¦ (1 < <5) ¦ (0xf); //0xaf
rIICADD = 0x10; //2410 slave address = [7:1]
rIICSTAT = 0x10; //IIC bus data output enable(Rx/Tx)
Uart_Printf("Write test data into AT24C02\n");
for(i=0;i <256;i++)
_Wr24C080(0xa0,(U8)i,i);//void _Wr24C080(U32 slvAddr,U32 addr,U8 data)
for(i=0;i <256;i++)
data[i] = 0;
Uart_Printf("Read test data from AT24C02\n");
for(i=0;i <256;i++)
_Rd24C080(0xa0,(U8)i,&(data[i]));
for(i=0;i <8;i++)
{
for(j=0;j <8;j++)
Uart_Printf("%2x ",data[i*8+j]);
Uart_Printf("\n");
}
Uart_Printf("OK! Write data is same to Read data!\n");
rGPEUP = save_PE;
rGPECON = save_E;
}
void _Wr24C080(U32 slvAddr,U32 addr,U8 data)
{
_iicMode = WRDATA;
_iicPt = 0;
_iicData[0] = (U8)addr;
_iicData[1] = data;
_iicDataCount = 2;
rIICDS = slvAddr; //0xa0
//Master Tx mode, Start(Write), IIC-bus data output enable
//Bus arbitration sucessful, Address as slave status flag Cleared,
//Address zero status flag cleared, Last received bit is 0
rIICSTAT = 0xf0;
//Clearing the pending bit isn't needed because the pending bit has been cleared.
while(_iicDataCount!=-1)
Run_IicPoll();
_iicMode = POLLACK;
while(1)
{
rIICDS = slvAddr;
_iicStatus = 0x100; //To check if _iicStatus is changed
rIICSTAT = 0xf0; //Master Tx, Start, Output Enable, Sucessful, Cleared, Cleared, 0
rIICCON = 0xe0;//0xaf; //Resumes IIC operation. //hzh
while(_iicStatus==0x100)
Run_IicPoll();
if(!(_iicStatus & 0x1))
break; //When ACK is received
}
rIICSTAT = 0xd0; //Master Tx condition, Stop(Write), Output Enable
rIICCON = 0xe0;//0xaf; //Resumes IIC operation. //hzh
Delay(1); //Wait until stop condtion is in effect.
//Write is completed.
}
[解决办法]
1、“IIC Test(Polling) using AT24C02” 那么 AT24C02 这个芯片有自己的IIC 地址 也许是你这里的0XA0 吧
2、IIC标准中 读写 操作时通过地址字节的 最末位来确认的, Bit 0 =0 代表IIC写 Bit 0 = 1 代表 IIC 读取At24C02操作,
详细请先看IIC协议标准 和 芯片资料的 IIC 部分讲解。