void I2c0Init(uint32 Fi2c) { if (Fi2c > 400000) Fi2c = 400000; PINSEL0 = (PINSEL0 & (~0xF0)) | 0x50; // 不影响其它管脚连接 I2C0SCLH = (Fpclk/Fi2c + 1) / 2; // 设定I2C时钟 I2C0SCLL = (Fpclk/Fi2c)/2; I2C0CONCLR = 0x2C; I2C0CONSET = 0x40; }
/****************************************************** * 采用类似串口的发送方式 * * * * *******************************************************/ void Command_Aic23(uint8 sla,uint8 subaddr, uint8 data) { uint8 sub=0;;
// I2C0CONCLR = 1<<3; I2C0CONSET = (1<<5)|(1<<6); while(1) { switch(I2C0STAT & 0xf8) { case 0x08: I2C0DAT = sla ; // 0位为0 I2C0CONCLR = 1<<3; break;
case 0x10: I2C0DAT = sla ; I2C0CONCLR = 1<<3; break; case 0x18: I2C0DAT = subaddr; I2C0CONCLR = 1<<3 ; break; case 0x28: if(sub==1) { I2C0CONCLR =0x28; return; } I2C0DAT = data; I2C0CONCLR = 1<<3 ; sub=1; break; default : I2C0CONCLR =0x28; return; break; } //SWITCH } // WHILE(1)
} 问题是每次执行完0X18分支之后就出错,望各位高手指点 |