AnsweredAssumed Answered

stm32f4 i2c pcf8574

Question asked by Kenny on Jun 29, 2013
Latest reply on Jun 29, 2013 by Kenny
Hi there,

I got stuck on communicating with a PCF8574....

I know that i have the address right, because i connected the chip to my Arduino for testing.

The program gets stuck on while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

Here is the code
GPIO_InitTypeDef GPIO_InitStruct;
    I2C_InitTypeDef I2C_InitStruct;
 
 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
         
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
 
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOB, &GPIO_InitStruct);
 
    // Connect I2C1 pins to AF
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); // SCL
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1); // SDA
         
    // configure I2C1
         
        I2C_DeInit(I2C1);
         
    I2C_InitStruct.I2C_ClockSpeed = 100000;
    I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStruct.I2C_OwnAddress1 = 0x00;
    I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_Init(I2C1, &I2C_InitStruct);
 
     
        // enable I2C1
    I2C_Cmd(I2C1, ENABLE);
         
 
        while(1)
        {
          while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
   
          //Send I2C1 START condition
          I2C_GenerateSTART(I2C1, ENABLE);
   
          //Test on I2C1 EV5 and clear it
          while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
     
          //Send slave Address for write
          I2C_Send7bitAddress(I2C1, 0x20, I2C_Direction_Transmitter);
   
          //Test on I2C1 EV6 and clear it
          while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
   
 
            //Send I2C1 slave register address
            I2C_SendData(I2C1, 0xFF);
     
            //Test on I2C1 EV8_2 and clear it
            while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
 
   
            //Send I2C1 STOP Condition
            I2C_GenerateSTOP(I2C1, ENABLE); 
            

I wrote this code for testing and i wanted to get all bits high by sending 0xFF

Am I doing something terribly wrong here?

Any help would be really appreciated

Outcomes