uint8 Write24C01(uint8 Addr,uint8 Data) { uint32 ii = 0x0; uint32 test; I20CONCLR = (1 << 2) | (1 << 3)| (1 << 5); // Çå³ýSTA,SI,AA±ê־λ I20CONSET = (1 << 5) | (1 << 6); // ÖÃλSTA,Æô¶¯I2C×ÜÏß // I20CONCLR = (1<<3) ; // I20CONSET = (1<<5); //-------------------------------------------------------------------------------- while ( ((I20STAT & 0xf8)!=0x08) && ((I20STAT & 0xf8)!=0x10) && (ii++<0xffff) ); //ÅжÏÓÐûÓз¢ËÍÆðʼÌõ¼þºÍÖظ´ÆðʼÌõ¼þ I20DAT = (at24c01a_addr<<1); // ·¢Ë͵ØÖ·,ûÓÐ×ÓµØÖ· I20CONCLR = 0x28 ; // 1<<5 ¹Ø±ÕÆô¶¯Î» ÎÊÌâµÄ¹Ø¼ü
//------------------------------------------------------------------------------------------
ii=0; while ( ((I20STAT & 0xf8) != 0x18) && ((I20STAT & 0xf8)!=0x20) && (ii++<0xffff) );//ÅжϵØÖ·ÓÐûÓÐû½ÓÊÕ²¢·µ»ØACKλ
if((I20STAT & 0xf8)==0x18) // Ö±½ÓдÊý¾Ý { I20DAT = Addr; I20CONCLR = 0x28; } else { I20CONCLR = 0x38; I20CONSET = 1<<4; return 0; } //-------------------------------------------------------------------------------------- ii=0; while ( ((I20STAT & 0xf8)!=0x28) && ((I20STAT & 0xf8)!=0x30) && (ii++<0xffff) );//ÅжÏÊý¾ÝÓÐûÓз¢Ëͳɹ¦²¢·µ»ØACKλ if(I20STAT==0x28) { I20DAT = Data; I20CONCLR = 0x28; } else { I20CONCLR = 0x38; I20CONSET = 1<<4; return 0; } //A点 //------------------------------------------------------------------- ii = 0; while ( ((I21STAT & 0xf8) != 0x28) && ((I21STAT & 0xf8)!=0x30) && (ii++<0x0ffff) ); test = I21STAT; if(test ==0x28 ) { I21CONSET = (1<<4); // Í£Ö¹I2C I21CONCLR = (0x28); // ÇåÁã SI ºÍ STA return 1; } else { I21CONSET = (1<<4); // Í£Ö¹I2C I21CONCLR = (0x28); // ÇåÁã SI ºÍ STA return 0; } } 说明: 1、用LPC2366的I2C0口控制AT24C01A。 2、test用于测试 3、程序运行,居然发现test = 0xf8 4、A点之前测试都正常 5、AT24C01A器件地址 = x1010 000(2进制) 请教:有可能是什么原因??
|