只需对TWI接口执行一下复位函数就可以了,如:
unsigned char AudioConfig[] = {
PWDC, 0x00FF,
LLVC, 0x1d,
RLVC, 0x1d,
LHVC, 0x78,
RHVC, 0x78,
AAPC, 0xf5,
DAPC, 0,
PWDC, 1,
DAIF, MS|FOR|LRP,
SARC, 0,
DIAC, ACT|RES
};
Reset_TWI(); /* reset the TWI interface */
TWI_MasterMode_Write( AIC23B_ADDRESS>>1, AudioConfig, 11, 2);
你可以连续执行TWI_MasterMode_Write 函数,用示波器测量信号和数据线的波形,或者发送一次TWI_MasterMode_Write函数,测量数据线上有没有ACK应答信号。
TWI_MasterMode_Write函数中,有一段等待应答的错误判断机制:
for (j = 0; j < (TWI_Length-1); j++)
{
/* # of transfers before stop condition */
while ((*pTWI_FIFO_STAT == XMTSTAT) && --timeout) /* wait to load the next sample into the TX FIFO */ // TAR37913
{
asm("nop;"); // TAR37913
asm("nop;");
asm("nop;");
ssync();
}
if(!timeout) // TAR37913
return;
*pTWI_XMT_DATA8 = *TWI_Data_Pointer++; /* load the next sample into the TX FIFO */
ssync();
}
如果你的代码每次都是超时跳出,那说明你的IIC还没有调通,检查硬件连接或者其他的什么。
另外你注意下IIC时钟和数据线上的上拉电阻。如果不行更换1.5K或者10K的试试,我遇到过这个情况。
个人感觉TWI接口用着不是很爽,感觉有BUG,不如IO模拟的好使,在一些官方例子代码中,你也会看到一些循环写入输入的代码,就是不断地写入配置数据,直到配置正确。感觉也是在避免这个BUG。