linux中I2C通信!
OT_U8 OT_I2C_PutByte(OT_U8 Byte){
OT_S8 Counter;
for (Counter=7; Counter>= 0; Counter--)
{
if ( Byte & (1<<Counter) )
{
OT_SDA_HIGH();
printk("i2c_key_sda = %d ****************\n",GPIOGetPinLevel(I2C_KEY_SDA));
}
else
{
OT_SDA_LOW(); /* address bit */
printk("i2c_key_sda = %d ****************\n",GPIOGetPinLevel(I2C_KEY_SDA));
}
OT_I2C_SCL_TOGGLE(); /* clock HI, delay, then LO */
}
OT_SDA_HIGH(); /* leave SDA HI */
OT_HDEL;
OT_SCL_HIGH(); /* clock back up */
OT_HAL_SDA_IN_MODE(); /* set i2c_key_sda input */
OT_HDEL;
//Byte=OT_HAL_BitRead_I2C_SDA(); /* get the ACK bit */
Byte=OT_GET_ACK_BIT();
printk("Byte = %d\n",Byte);
OT_SCL_LOW();
OT_SDA_HIGH(); /* leave with SDA HI */
if(Byte == 0)
return OT_SUCCESS; /* return OT_SUCCESS (ACK), or OT_FAILURE (NACK) */
return OT_FAILURE;
}
延时函数OT_HDEL :延时4微妙,用的udelay(4); 处理器是ARM9!
这是我的写一个字节的函数:问题是在我写完第八位时,等待从机应答,但是每次收到的是sda=1,从机不应答。应该怎样处理呢?请各位大侠帮帮忙啊。
页:
[1]