版主
你好。I2C接口调试不通过,想请教一下,是怎么回事,我用示波器测试输出的SCL口,硬件的从地址已经输出来了,但是没有数据输出。程序调用出错,C6747_I2C_write()返回值正常应该是0,怎么老是返回-1。感觉好像就没有将数据发送出去一样,好像是寄存器配置有问题,但仔细看了遍,也没发现是什么问题呀,请你多多帮忙,谢谢!
Int16 C6747_I2C_write( Uint16 i2c_addr, Uint8* data, Uint16 len )
{
C6747_wait( 10 ); // Short delay
for ( i = 0 ; i < len ; i++ )
{
I2C_ICDXR = data[i]; // Write
timeout = i2c_timeout;
do
{
if ( timeout-- < 0 )
{
C6747_I2C_reset( );
return -1;
}
} while ( ( I2C_ICSTR & ICSTR_ICXRDY ) == 0 );// Wait for Tx Ready
}
I2C_ICMDR |= ICMDR_STP; // Generate STOP
return 0;
}
俺又仔细看了一遍,在while ( ( I2C_ICSTR & ICSTR_ICXRDY ) == 0 );// Wait for Tx Ready
查看寄存值为I2C_ICSTR =0X1406.IRS位在寄存器ICMDR中已经置位了,根据提示
应该是The I2C has received or transmitted a START bit on the bus.可是需要怎么设置呢,我搞了两天了也没搞出来。
真的是无语了。。。。。。。寄存器设置如下:
I2C_ICMDR = 0; // Reset I2C
I2C_ICMDR = ICMDR_TRX // set for Transmitter mode
| ICMDR_MST; // Set for Master Write
I2C_ICSAR = i2c_addr; // Set I2C slave address
I2C_ICPSC = 9; // Prescale to get 7.5MHz I2C internal
I2C_ICCLKL = 15; // Config clk LOW for 100kHz
I2C_ICCLKH = 40; // Config clk HIGH for 100kHz
I2C_ICSTR = I2C_ICSTR;
while (!(I2C_ICIVR == 0));
I2C_ICMDR |= ICMDR_IRS; // Release I2C from reset
while (!(( I2C_ICSTR & ICSTR_BB ) == 0 ));
I2C_ICMDR |= ICMDR_STT;
//以上都是按TI手册中Configuring the I2C 步骤来的,已经核对了,没有发现问题
|