cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103x8 i2c2 smaple code

nb_pawar
Associate II
Posted on May 08, 2010 at 16:32

STM32F103x8 i2c2 smaple code

6 REPLIES 6
chikos332
Associate II
Posted on May 17, 2011 at 13:50

code for I2C2 is exactly the same as I2C1, absolutely no difference (just replace I2C1 by I2C2).

But may be you have a hardware issue:

  - Are you using an ST Eval board ?

  - Are you sure no other IP is using the  I2C2 pins ? and that a correct pull up resistors are connected to I2C2 pins?

  - If you wanna a simple demonstration code try the ST provided I2C examples (@ http://www.st.com/stonline/products/support/micro/files/stm32f10x_stdperiph_lib.zip  then go to folder ''STM32F10x_StdPeriph_Lib_V3.3.0\Project\STM32F10x_StdPeriph_Examples\I2C\Interrupt'')

  - For GPIO configuration (from ST provided examples):

  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure I2C1 pins: SCL and SDA ----------------------------------------*/

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configure I2C2 pins: SCL and SDA ----------------------------------------*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

Is this the kind of information you are looking for ?

damh
Associate II
Posted on May 17, 2011 at 13:50

DMA and interrupt handling is also different.

nb_pawar
Associate II
Posted on May 17, 2011 at 13:50

Thanks dear,

    yes it was a hardware issue i observed, but now i am facing another problem that with the same code i can write as well as read from the EEPROM by i2c_1 but EEPROM on i2c_2 replies only for writing procedure not for reading procedure completely so that i cant able to confirm whether the writing operation is ok or not.

chikos332
Associate II
Posted on May 17, 2011 at 13:50

Hi,

could you please share with us the hardware issue you found? it may be useful for someone else?

Thanks.

chikos332
Associate II
Posted on May 17, 2011 at 13:50

Hi again,

When you write to an EEPROM, in some cases, no error status is returned even when write operation is incorrect. So the read operation is the most critical.

Your problem seems to be too ''large'', but I think it is probably still a HW issue. I think the main questions are:

 - Are you sure about the used EEPROM address ?

 - Are you sure about the pullups on I2C2 pins ? are there any other component using the same pins as I2C2 on your board?

 - Are you using the same I2C speed for both I2Cs?

 - Do you power off the EEPROM between the use of I2C1 and I2C2?

 - Are you using a separate EEPROM for each I2C? and in this case, are the two EEPROM identical (type, speed, address, ...).

I hope these questions may help you investigate the issue 🙂

nb_pawar
Associate II
Posted on May 17, 2011 at 13:50

Hi

That issue is solved.

its  a small mistake on firmware side while passing i2c number to library function.

In hardware point of view there was a dry soldering of microcontroller thats why EEPROM not getting clock signal.