初始化NXP2103的I2C模块,程序如下:
uchar Init_i2c(void)
{
uchar i2c_stat;
i2c_stat=4;
I2C0CONSET =0X40; //使能为主发送器模式
I2C0CONCLR =0X2C;
I2C0SCLL =(F_pclk/fi2c+1)/2;
I2C0SCLH =(F_pclk/fi2c)/2;
while((I2C0STAT&0x08)==0x00); //等待中断
I2C0DAT =0Xa0;
I2C0CONSET &=~0x08; //清除中断标志位
//开始发送数据
i2c_stat=0;
if(I2C0STAT==0x18)
{
i2c_stat=1;
}
else if(I2C0STAT==0x20)
{
i2c_stat=2;
}
else if(I2C0STAT==0x38)
{
i2c_stat=3;
}
else if(I2C0STAT==0xf8)
{
i2c_stat=4;
}
return i2c_stat;
}
结果:I2C0STAT的值总是0XF8,这是为何? |