LPC23xx通过I2C接口读写AT24C64
else//sendNOACK
if(ACK==0)
{
I20CONCLR=I2CONCLR_AAC;
}
I20CONCLR=I2CONCLR_SIC|I2CONCLR_STAC;// clear SISAT
while (!(I20CONSET&I2CONCLR_SIC));// wait interrupt flag ( waiting for SI==1)
if(ACK==1)
{
if((I20STAT&0xF8)==0x50) //receive data and get ack
{
*RcvData=I20DAT;
return TRUE;
}
else
return FALSE ;
}
else
if(ACK==0)
{
if((I20STAT&0xF8)==0x58) //receive data and get NoAck (the last data you want to get)
{
*RcvData=I20DAT;
return TRUE;
}
else
return FALSE ;
}
return FALSE ;
}
DWORD I2C_ReadNByte(UINT16 SubAddr ,UINT8 *Data,UINT8 Length)
{
BYTEi;
if (!I2CStart())
{
return FALSE;
}
if(I20STAT==0x08)/*已发送起始条件*/
{
I2C_SendByte(AT24C64NW);// Device Address
if(I20STAT==0x18) /*已发送SLA+W,已接收ACK */
{
I2C_SendByte((SubAddr>>8)&(0x00FF));
if(I20STAT==0x28)/*已发送SubAddr_H,已接收ACK */
{
I2C_SendByte(SubAddr&(0x00FF));
if(I20STAT==0x28) /*已发送SubAddr_L,已接收ACK */
{
if (I2CStartAgain())//发送重复起始条件切换为主接受模式
{
I2C_SendByte(AT24C64NR);
if(I20STAT==0x40)/*已发送SLA+R,已接收ACK*/
{
for(i=0;i { if(!(I2C_ReadByte(1,&Data[i]))) { return FALSE; } } if( !( I2C_ReadByte(0, &Data[Length-1]) ) ) //读最后一个数据 { return FALSE; } if (I2CStop())//发送停止条件 { return TRUE; } return FALSE; } return FALSE; } return FALSE; } return FALSE; } return FALSE; } return FALSE; } return FALSE; }
LPC23xxI2C接口读写AT24C6 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)