cancel
Showing results for 
Search instead for 
Did you mean: 

F429 I2C interface init

kostas
Associate II
Posted on May 01, 2014 at 17:52

#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 wronghere? 
 
 
 

9 REPLIES 9
stm322399
Senior
Posted on May 01, 2014 at 18:06

You probably miss ''stm32f4xx.h''

kostas
Associate II
Posted on May 01, 2014 at 18:15

Yea, i didnt included this header, but still got the same errors after including it.

Posted on May 01, 2014 at 18:19

You need to examine the example/template projects supplied with the firmware libraries. How the include paths are specified to the tool chain, the defines passed on the command line and the structure with the stm32f4xx_conf.h in the project directory.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
neo911
Associate II
Posted on May 01, 2014 at 18:36

Could be better like that:

    GPIO_InitTypeDef GPIO_InitStruct;        // instead of GPIO_InitStructure

     ...

    GPIO_Init(GPIOB, &GPIO_InitStruct);   // same change

Rgds.

kostas
Associate II
Posted on May 01, 2014 at 18:53

Thank you, i didnt noticed this one!!

Pins errors still remain.
neo911
Associate II
Posted on May 01, 2014 at 19:13

what about

GPIO_PinAFConfig(GPIOB, GPIO_Pin_6, GPIO_AF_I2C1); // instead of GPIO_Pin6

GPIO_PinAFConfig(GPIOB, GPIO_Pin_9, GPIO_AF_I2C1); // instead of GPIO_Pin9   Because the first use of them seems ok, when you initialize the structure in GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9;  ?   Rgds  

kostas
Associate II
Posted on May 01, 2014 at 19:20

Ohh Gosh!! So blind!! will be more careful next time!

Thank you for helping me out, have a nice day! 
neo911
Associate II
Posted on May 01, 2014 at 20:02

Have a nice day too! If I can help again, I'll be glad to.

kostas
Associate II
Posted on May 03, 2014 at 11:00

Looks like im gonna need a little bit more.

It looks like start signal never issued because I2C1 busy flag is always SET

https://github.com/papadkostas/BH1750

@BH1750.c Line 5 function I2C_start(I2C1,...);

while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));

Always return a busy status!

The module im using works fine with the arduino board.