cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get I2C working

drebbe
Associate II
Posted on March 15, 2012 at 05:57

I'm trying to get I2C working, I've verified I can manually toggle the pins at 400KHz with a pull up resistor. I can't seem to get the I2C code to work correctly though.

    input_clock = CLK_GetClockFreq()/1000000;

    I2C_DeInit();

    I2C_Cmd(ENABLE);

    I2C_Init(I2C_MAX_STANDARD_FREQ,

        0xA0,

        I2C_DUTYCYCLE_2,

        I2C_ACK_CURR,

        I2C_ADDMODE_7BIT,

        input_clock);

    (void)I2C->SR1;

    (void)I2C->SR3;    

    while (1)

    {

        while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));

        I2C_GenerateSTART(ENABLE);

        while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));

        I2C_Send7bitAddress(0xA0, I2C_DIRECTION_TX);

        while (!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

        I2C_SendData(0xCA);

        while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));

        I2C_GenerateSTOP(ENABLE);

    }

The code always get stuck at ''

while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));

''

I've read the errata and don't really see anything similar to this. Also I currently don't have pull-up resistors on the lines while using this code, would this cause the I2C code to error out and always say its busy?

#i2c-busy-bit-set
0 REPLIES 0