以下是我调试通过的程序,对IIC写操作,用自带的库,请参考
/*******************************************************************************
; name of function:
*******************************************************************************/
void Init_I2C_Prog(void)
{
u8 Input_Clock = 0;
/* Get system clock frequency */
Input_Clock = CLK_GetClockFreq()/1000000;
/* Optional: put here as example only */
I2C_DeInit();
/* Enables the I2C peripheral */
I2C_Cmd(ENABLE);
/* Initialize the I2C */
I2C_Init(
100000, //OutputClockFrequencyHz
0xA0, //OwnAddress
I2C_DUTYCYCLE_2, //DutyCycle
I2C_ACK_CURR, //Ack
I2C_ADDMODE_7BIT, //AddMode
Input_Clock //InputClockFrequencyMHz
);
}
/*******************************************************************************
; name of function:
*******************************************************************************/
void I2C_WriteData_Prog(u8 tData)
{
/* Send START condition */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_START_SENT));
/* Send slave Address for write */
I2C_Send7bitAddress(DAC081_ADR0FL_Adr, I2C_DIRECTION_TX);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
/* Send data */
I2C_SendData(tData);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STOP Condition */
I2C_GenerateSTOP(ENABLE);
}