AnsweredAssumed Answered

F429 I2C interface init

Question asked by papadopulos.kostas on May 1, 2014
Latest reply on May 3, 2014 by papadopulos.kostas
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
 
void I2C1_Init(){
 
    /* Enable Peripheral Clock for I2C1 */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
 
    /* Enable Peripheral Clock for SDA SCL Pins(GPIOB) */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
 
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9;
    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_UP;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
 
    /* Connect I2C1 pins to AF */
    GPIO_PinAFConfig(GPIOB, GPIO_Pin6, GPIO_AF_I2C1);
    GPIO_PinAFConfig(GPIOB, GPIO_Pin9, GPIO_AF_I2C1);
 
    /* configure I2C1 */
    I2C_InitTypeDef I2C_InitStruct;
    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_Disable;
    I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_Init(I2C1, &I2C_InitStruct);
 
    /* enable I2C1 */
    I2C_Cmd(I2C1, ENABLE);
}
 
int main(){
  SystemInit();
  I2C1_Init();
  while(1){
  }
}

I followed up the instructions from the library provided by ST 
But while i compile this im getting the following errors 
[cc] D:\My Documents\Desktop\STM32F429ZI\DefaultProject\main.c: In function 'I2C1_Init':
       [cc] D:\My Documents\Desktop\STM32F429ZI\DefaultProject\main.c:14:2: error: 'GPIO_InitStruct' undeclared (first use in this function)
       [cc]   GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9;
       [cc] D:\My Documents\Desktop\STM32F429ZI\DefaultProject\main.c:14:2: note: each undeclared identifier is reported only once for each function it appears in
       [cc] D:\My Documents\Desktop\STM32F429ZI\DefaultProject\main.c:22:26: error: 'GPIO_Pin6' undeclared (first use in this function)
       [cc]   GPIO_PinAFConfig(GPIOB, GPIO_Pin6, GPIO_AF_I2C1);
       [cc]                           ^
       [cc]   ^
       [cc] D:\My Documents\Desktop\STM32F429ZI\DefaultProject\main.c:23:26: error: 'GPIO_Pin9' undeclared (first use in this function)
       [cc]   GPIO_PinAFConfig(GPIOB, GPIO_Pin9, GPIO_AF_I2C1);
       [cc]                           ^


BUILD FAILED
Total time: 1 second

What am i doing wrong here?


Outcomes