2014-05-01 08:52 AM
#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?
2014-05-01 09:06 AM
You probably miss ''stm32f4xx.h''
2014-05-01 09:15 AM
Yea, i didnt included this header, but still got the same errors after including it.
2014-05-01 09:19 AM
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.
2014-05-01 09:36 AM
Could be better like that:
GPIO_InitTypeDef GPIO_InitStruct; // instead of GPIO_InitStructure
... GPIO_Init(GPIOB, &GPIO_InitStruct); // same change Rgds.2014-05-01 09:53 AM
Thank you, i didnt noticed this one!!
Pins errors still remain.2014-05-01 10:13 AM
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; ? Rgds2014-05-01 10:20 AM
Ohh Gosh!! So blind!! will be more careful next time!
Thank you for helping me out, have a nice day!2014-05-01 11:02 AM
Have a nice day too! If I can help again, I'll be glad to.
2014-05-03 02:00 AM
Looks like im gonna need a little bit more.
It looks like start signal never issued because I2C1 busy flag is always SEThttps://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.