AnsweredAssumed Answered

STM32F103 and I2C issue - No ACK from slave

Question asked by suzzi.gianluca on Feb 22, 2013
Latest reply on Oct 31, 2014 by van_kuilenburg.jan
Hi everyone, first of all i've to tell you that i'm new with I2C bus.
I'm using I2C1 on STM32F103 ARM to communicate with an I2C eeprom (24LC256).
I can see both SCL and SDA on my scope but it seems there is a problem with the ACK at the ninth clock.
I've made the same test with a lux sensor MAX44009 and i can't be able to see any ACK at all.

The testing function i use is:

void STM32_I2C_test(void)
{
uint8_t I2C_address;
uint32_t I2C_speed;
 
GPIO_InitTypeDef    GPIO_InitStructure;
I2C_InitTypeDef     I2C_InitStructure;
 
I2C_address = 0xA0; //
//address = 0x94;   //
I2C_speed = 1000;   // 1000Hz
 
        /*enable I2C*/
    I2C_Cmd(I2C1,ENABLE);
    /* I2C1 clock enable */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
 
    /* I2C1 SDA and SCL configuration */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    //SCL is pin06 and SDA is pin 07 for I2C1
 
    /* I2C1 configuration */
    I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;
    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStructure.I2C_OwnAddress1 = 0x00;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStructure.I2C_ClockSpeed = I2C_speed ;
    I2C_Init(I2C1, &I2C_InitStructure);
 
    //
    /* check start bit flag */
    while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
      /* initiate start sequence */
    I2C_GenerateSTART(I2C1,ENABLE);
    while(!I2C_GetFlagStatus(I2C1, I2C_FLAG_SB));
    /*send write command to chip*/
    I2C_SendData(I2C1,I2C_address);//I2C_Send7bitAddress(I2C1, address, I2C_Direction_Transmitter);
    /*check master is now in Tx mode*/
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
    /*mode register address*/
    I2C_SendData(I2C1, 0x02);
    /*wait for byte send to complete*/
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
    /*clear bits*/
    I2C_SendData(I2C1, 0x00);
    /*wait for byte send to complete*/
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
    /*generate stop*/
    I2C_GenerateSTOP(I2C1, ENABLE);
    /*stop bit flag*/
    while(I2C_GetFlagStatus(I2C1, I2C_FLAG_STOPF));
}

I've attached also the signals from my scope. I've pulled up both SCL and SDA with 10k resistors (but i've tried also with 4k7 with no effect).

i2c2.png

Can you halping me understand where i'm wrong?

Thank's and sorry for my english.

Attachments

Outcomes