当我发送起始位时,SI位置为,当发送从地址以及读写位时,SI不置位,求教
void I2C_Init(uint32 F_I2C)
{
PINSEL0 = (PINSEL0 & 0xfffff0f) | 0x50;
if(F_I2C > 400000)
F_I2C = 40000;
I2SCLH = (Fpclk / F_I2C + 1) / 2;
I2SCLL = (Fpclk / F_I2C) / 2;
I2CONCLR = 0x2C;
I2CONSET = I2EN;
}
uint8 W_E2PROM(uint8 sla, uint8 slaveAddr, uint8 * pWriteData, uint8 num)
{
uint8 i;
I2CONCLR = AA | SI | STA;
I2CONSET = I2EN | STA;
while((I2CONSET & SI) == 0);
if(I2STAT != 0x08)
{
I2CONSET = STO;
return (I2STAT);
}
I2CONCLR = SI | STA;
I2DAT = sla & 0xfe;
while((I2CONSET & SI) == 0); //就是卡在这里执行不下去了,我看视频时有提到PLL设置,但设置了,还是不行,江湖救急,求教
if(I2STAT != 0x18)
{
I2CONSET = STO;
return (I2STAT);
}
I2CONCLR = SI;
I2DAT = slaveAddr;
while((I2CONSET & SI) == 0);
if(I2STAT != 0x28)
{
I2CONSET = STO;
return (I2STAT);
}
for(i = num; i > 0; i--)
{
I2CONCLR = SI;
I2DAT = *pWriteData++;
while((I2CONSET & SI) == 0);
if(I2STAT != 0x28)
{
I2CONSET = STO;
return (I2STAT);
}
}
I2CONCLR = SI;
I2CONSET = STO;
return (1);
}
|