i2cData[0] = (SlaveAddress << 1) | 0;//器件地址+写
i2cData[1] = 0x00;//word addr
DataSz = 2;
StartI2C1();//Send the Start Bit
IdleI2C1();//Wait to complete
Index = 0;
while( DataSz )
{
MasterWriteI2C1( i2cData[Index++] );
IdleI2C1(); //Wait to complete
DataSz--;
if( I2C1STATbits.ACKSTAT )
break;
}
RestartI2C1(); //Send the Restart condition
i2c_wait(10);
//wait for this bit to go back to zero
IdleI2C1(); //Wait to complete
MasterWriteI2C1( (SlaveAddress << 1) | 1 ); //transmit read command
IdleI2C1(); //可能死在这里
i2cbyte = MasterReadI2C1(); //读一个字节//可能死在这里
LATDbits.LATD0 = 0;//LED0
StopI2C1(); //Send the Stop condition
IdleI2C1(); //Wait to complete
printf("verify\n");
// verify write and read I2C EEPROM (single byte)
if( i2cbyte != 0xAC )
{
while(1) //error: verify failed
{
if(TX_FLAG == 10)
{
TX_FLAG = 0;
printf("verify failed!\n");
}
}
} |