2011-06-01 01:00 PM
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. Stephan2014-06-02 07:56 AM
One presumes PB8/9
Make sure you have, or enable, pull-ups on the pins in question. It's real hard to make material suggestions about your hardware setup and connectivity with such vague hand waving. An unpublished errata in the design is about the last thing I have on the list of possible issues here.2015-03-02 11:14 AM
2015-03-02 12:24 PM
hi can some one help me getting the I2c code for stm32f205xx controller .
Well there are a handful of examples in the SPL, you could start there. STM32F2xx_StdPeriph_Lib_V1.1.0\Project\STM32F2xx_StdPeriph_Examples\I2C\I2C_TwoBoards Review also the implementation on F2/F4 EVAL boards.