STM8S103k3 I2C在STVD+cosmic下编译成功,
Debug时使用simulator程序正常,用ST—LINK链接到MCU时,
停在while(!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT))处;
刚接触ST芯片,很多东西都不了解。不知是何故,望高人指点!
uCHAR I2CWriteByte(uCHAR cDevAddr, uCHAR cReg,uCHAR cData)
{
//I2cInit();
I2C_GenerateSTART(ENABLE);
/*EV5*/
while(!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
I2C_Send7bitAddress(cDevAddr,I2C_DIRECTION_TX );
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
I2C_SendData(cReg);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_SendData(cData);
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTOP(ENABLE);
} |