AnsweredAssumed Answered

I2C Configuration on STM32F2xx

Question asked by de_wit.stephan on Jun 1, 2011
Latest reply on Mar 2, 2015 by Clive One
I am using a STM32F217 based board with the CrossStudio tool chain.  I am having problems configuring the I2C bus correctly.  No matter what I do I cannot measure any signals on the data or clock lines.  My configuration code is below.

 #define I2C1_PORT             GPIOB
 #define I2C1_SCL_PIN         GPIO_Pin_8
 #define I2C1_SDA_PIN         GPIO_Pin_9

void I2C_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  I2C_InitTypeDef I2C_InitStructure;

  /* Enable I2C1 and I2C1_PORT & Alternate Function clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

  /* Reset I2C1 IP */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
 
  /* Release reset signal of I2C1 IP */
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE); 

  /* I2C1 SCL and SDA pins configuration */
  GPIO_InitStructure.GPIO_Pin = I2C1_SCL_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(I2C1_PORT, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = I2C1_SDA_PIN;
  GPIO_Init(I2C1_PORT, &GPIO_InitStructure);
 
  /* Alternate function remapping */
  GPIO_PinAFConfig(I2C1_PORT, I2C1_SCL_PIN, GPIO_AF_I2C1);
  GPIO_PinAFConfig(I2C1_PORT, I2C1_SDA_PIN, GPIO_AF_I2C1);

  /* I2C De-initialize */
  I2C_DeInit(I2C1);

  /* I2C configuration */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  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 = 400000;

  /*!< I2C Initialize */
  I2C_Init(I2C1, &I2C_InitStructure);

  /* I2C ENABLE */
  I2C_Cmd(I2C1, ENABLE);
}

I cannot get into master mode even when using the "I2C_GenerateSTART(I2C1, ENABLE);" command.  It seems like my configuration is incomplete since I don't measure any SDA/SCK signals.  I have similar, working, code for a STM32F107 based board but the '217 confounds me.

Thanks for any help.
Stephan

Outcomes