打印

急!!wince调试I2C总线收不到从设备应答信号!

[复制链接]
1752|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mjx91282041|  楼主 | 2012-7-14 21:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我在调试一个I2C驱动,用IO口模拟的I2C总线,目前ADS调试裸机通过,但是加载到系统里面,总线时序就不对了,总收不到从设备发出的应答信号,即使我发送设备地址也不到应答。请问高手帮帮忙呀!我调试快两周了,没搞定呀!
下面是我的写字节函数,延时已经使用了精确延时,目前是20us(因为在ADS下调试通过),1us-60us延时都试过。
[code=C/C++][/code]
//----------------------------------------------------------------------------------
unsigned char I2c_WriteByte(unsigned char value)
//----------------------------------------------------------------------------------
// writes a byte on the Sensibus and checks the acknowledge  
{  
int error=0, i1=0, i2=0;
// unsigned char ub;
for(i2 = 0; i2 < 8; i2++ )
{ // setup data onto SDA
  if(value & 0x80){
   SDA_Set;    //SetSDA( 1 );
  }
  else{
   SDA_Clear;   //SetSDA( 0 );
  }
  Delay_us(1);    //I2C timing: data setup time > 200ns
  
  // issue a clock
  SCL_Set;     //SetSCL( 1 );
  Delay_us(1);    //I2C timing: SCL high time > 0.6us
  SCL_Clear;    //SetSCL( 0 );
  Delay_us(2);    //I2C timing: SCL low time > 1.3us
  value= value<< 1;
}
//check ACK(Low state) from I2C device
SDA_OutDisable;    //set SDA as input
  
Delay_us(1);     //I2C timing: data(from I2C device) setup time > 200ns
SCL_Set;      //SetSCL( 1 );    // issue a clock
Delay_us(1);     //I2C timing: SCL high time > 0.6us
if(s2440IOP->rGPFDAT>>1)     //read ACK_BIT issued from I2C device
{
  // NO ACK, so setup STOP condition
  SCL_Set;     //SetSCL( 1 );
  Delay_us(1);    //I2C timing: stop setup timing > 0.6us
  SDA_Set;     //SetSDA( 1 ); SDA is in input status!
  return -(i1+1);    // no acknowledgement -> failed
}
SCL_Clear;     //SetSCL( 0 );
Delay_us(2);     //I2C timing: SCL low time > 1.3us
//check ACK passed, config SDA as output for further outputing
SDA_OutEnable;
SDA_Set;
return 0;;
  
}

相关帖子

沙发
mjx91282041|  楼主 | 2012-7-16 09:06 | 只看该作者
顶顶顶顶顶顶顶

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

12

主题

54

帖子

1

粉丝