用的是AW32,外部晶振9.8304MHz,FBE模式,总线频率4.9152MHz,IIC模块配置如下: IIC1C=0x80; IIC1F=0x50;
与at24c64通信,写子程序如下:
tagAdr sAdr; #define gAdr sAdr.EepromAdr #define gAdrH sAdr.adr16.AdrH #define gAdrL sAdr.adr16.AdrL
void IICWriteByte(word adr, byte dt){ gAdr=adr; IIC1C_TXAK=0; IIC1C|=0x30; //MST=1 TX=1 and generate STARTcondition IIC1D=IIC_SLAVE_ADR; while(!IIC1S_IICIF); //wait untill TX completed IIC1S_IICIF=1; //clear IICIF while(IIC1S_RXAK); //check for slave ack IIC1D=gAdrH; while(!IIC1S_IICIF); IIC1S_IICIF=1; while(IIC1S_RXAK); IIC1D = gAdrL; while(!IIC1S_IICIF); IIC1S_IICIF=1; while(IIC1S_RXAK); IIC1D=dt; while(!IIC1S_IICIF); IIC1S_IICIF=1; while(IIC1S_RXAK); IIC1S_IICIF=1; IIC1C_MST=0; }
void IICWriteN(word adr,byte *dt,byte n){ //此函数全速执行不正常,单步执行则正常!
byte i; for(i=0;i<n;++i) { IICWriteByte(adr+i,dt); } } 奇怪的是在调用IICWriteN时,如果全速执行,则会在while(IIC1S_RXAK);一直执行,即没收到从机的ACK,但是单片跳进IICWriteN函数执行则正常。为什么? |