自己写了一下没有成功,下面是给的例程,用中断的方法来发送一个Byte,红色的部分都好理解,分别写器件地址,子地址,数据,每发送完一个字节产生一次中断,发完了停止总线。 问题是,它上面的每个字节发完之后都不等ACK,直到发完,总线停止了以后,来到蓝色部分,在这里等ACK???而且这时还是设rIICSTAT=0xf0;就是主器件发送模式,再发送一次器件地址,然后等ACK,这是从何说起啊?? 另外,44B0是否无法用I/O口来模拟I2C了?要频繁更改I/O口的属性,似乎时间上来不及,不知道为什么ARM的I/O口都要这样设计,不像51的是输入输出的??
void Wr24C040(U32 slvAddr,U32 addr,U8 data) { _iicMode=WRDATA; _iicPt=0; _iicData[0]=(U8)addr; _iicData[1]=data; _iicDataCount=2; rIICDS=slvAddr;//0xa0 rIICSTAT=0xf0; //MasTx,Start while(_iicDataCount!=-1);
_iicMode=POLLACK; while(1) { rIICDS=slvAddr; _iicStatus=0x100; rIICSTAT=0xf0; //MasTx,Start rIICCON=0xaf; //resumes IIC operation. while(_iicStatus==0x100); if(!(_iicStatus&0x1)) break; // when ACK is received } rIICSTAT=0xd0; //stop MasTx condition rIICCON=0xaf; //resumes IIC operation. Delay(1); //wait until stop condtion is in effect.
//write is completed. }
void __irq IicInt(void) { U32 iicSt,i; rI_ISPC=BIT_IIC;
switch(_iicMode) { case POLLACK: _iicStatus=iicSt; break;
case WRDATA: if((_iicDataCount--)==0) { rIICSTAT=0xd0; //stop MasTx condition rIICCON=0xaf; //resumes IIC operation. Delay(1); //wait until stop condtion is in effect. //The pending bit will not be set after issuing stop condition. break; } rIICDS=_iicData[_iicPt++]; //_iicData[0] has dummy. for(i=0;i<10;i++); //for setup time until rising edge of IICSCL rIICCON=0xaf; //resumes IIC operation. break;
default: break; } } |