cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Bus not pulsing after the start condition

ngoclt
Associate
Posted on October 31, 2012 at 21:57

I am communicating with a slave device and after the generation of the start condition, I am not seeing SCL and SDA pulsing. Below is the code: 

void DS2482_Init(void)

{

        GPIO_InitTypeDef    GPIO_InitStructure;

        I2C_InitTypeDef     I2C_InitStructure;

        

        /* Enable peripheral clock */

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);

        /* Enable GPIOB clock */

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

     

        /* Configure I2C2_SCL and I2C2_SDA */

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

        GPIO_Init(GPIOB, &GPIO_InitStructure);

        

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

        GPIO_Init(GPIOB, &GPIO_InitStructure);

        

        /* Enable I2C2 reset state */

        //RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);

        /* Release I2C2 from reset state */

        //RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);

                

        I2C_DeInit(DS2482_I2C);

        

        /* DS2482 peripheral configuration */

        I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; 

        I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;

        I2C_InitStructure.I2C_OwnAddress1 = DS2482_I2C_ADDRESS;

        I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

        I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

        I2C_InitStructure.I2C_ClockSpeed = DS2482_I2C_SPEED;

        /* enable the I2C peripheral */

        I2C_Cmd(DS2482_I2C, ENABLE);

        I2C_Init(DS2482_I2C, &I2C_InitStructure);       

}

int DS2482_channel_select(int channel)

{

    // select the 1-wire channel on DS2482-800

    // Returns: TRUE if channel selected

    //          FALSE if device not detected

    unsigned char ch, ch_read, check;

    

    /* while the bus is busy */

    while(I2C_GetFlagStatus(DS2482_I2C, I2C_FLAG_BUSY));

    

    /* send START condition */

    I2C_GenerateSTART(DS2482_I2C, ENABLE);

    

    /* test on EV5 and clear it */

    while(!I2C_CheckEvent(DS2482_I2C, I2C_EVENT_MASTER_MODE_SELECT));

    

    //I2C_AcknowledgeConfig(DS2482_I2C, ENABLE);

    

    /* Send DS2482 address for write */

    I2C_Send7bitAddress(DS2482_I2C, DS2482_I2C_ADDRESS, I2C_Direction_Transmitter);

#i2c-example-stm32
3 REPLIES 3
neoirto
Associate II
Posted on November 01, 2012 at 11:41

I had the same problem yesterday : found a fix like this :

I2C_Send7bitAddress(DS2482_I2C, DS2482_I2C_ADDRESS, I2C_Direction_Transmitter);

becomes :

I2C_Send7bitAddress(DS2482_I2C, (DS2482_I2C_ADDRESS<<1), I2C_Direction_Transmitter);

It appears you need to shift manually... It's quite a bit strange with a complete library from ST. Is there any i2c config flag to set a different way ?
ngoclt
Associate
Posted on November 01, 2012 at 20:41

Thanks for pointing it out! I double checked and yes, the slave address needs to be shifted. It is working now :).

Amel NASRI
ST Employee
Posted on February 25, 2013 at 12:02

Hi Stephane,

This shouldn't be a bug as the address is a user defined parameter.

The correct format is specified in reference manuals (The 7 bit device address...is placed in the most significant bits of the byte. The eighth bit can be a zero or one.).

Best Regards,

ST.MCU

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.