高手赐教,QG8的IIC从PB6PB7搬到P2,PA3后,无法写入IICD。
- UID
- 784986
- 性别
- 男
|
高手赐教,QG8的IIC从PB6PB7搬到P2,PA3后,无法写入IICD。
如题,我原来用PB6\PB7做IIC通讯,效果挺好的。后来B6\PB7改作晶振输入,IIC改为PA2\PA3,即:SOPT2 = 0x00; 结果死活调试不成功。每次走到IICD=0X70后在后面的等待中停下。后来发现:IICD=0X70;后,相应IICD寄存器仍然为0,不知道为何,请高人指点。写IIC函数如下:void iic_write(unsigned char iic_ad,unsigned char iic_data)
{
IICS_IICIF = 1; //++
temp = (page_n & 0x07) << 1;
IICC_TX = 1; // Set transmit mode;
//-------start of transmit first byte to IIC bus-----
IICC_MST = 1; // Start transfer - Master bit = 1;
// IIC1D = sl_addr | temp; // send "Write" + high address;
if(iic_chnl==eprm)
{
IICD = 0xa0;
}
else
IICD = 0x70; //MAX695_A_地址 0x70= 0111000+0或//24c64Adresss:0xa0=BIT1010,0000
while (!(IICS_IICIF));
IICS_IICIF = 1;
while (IICS_RXAK); // wait for ACK from slave;
//-----Slave ACK occured------------
if(iic_chnl==eprm)
{
IICD = page_n; // send high address byte;
while (!(IICS_IICIF));
IICS_IICIF = 1;
while (IICS_RXAK); // wait for ACK from slave;
}
//-----Slave ACK occured------------
IICD = iic_ad; // send address byte;
while (!(IICS_IICIF)); // wait till data transfered;
IICS_IICIF = 1;
while (IICS_RXAK); // wait for ACK from slave;
//-----Slave ACK occured------------
IICD = iic_data; // write data byte into led driver;
while (!(IICS_IICIF)); // wait till data transfered;
while (IICS_RXAK); // wait for ACK from slave;
IICC_MST = 0; // STOP bit;
WaitNms(20);
} |
|
|
|
|
|