cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L-Discovery communicate in I2C with M24LR64

Posted on April 24, 2012 at 09:13

Hello everybody,

I have some troubel to communicate with m24LR64. I use a STM32L- Discovery.

I try to see something in the oscilloscope but nothing, could you help me to see what is wrong in my code:

#define I2C2_SLAVE_ADDRESS7     0xA0   // EEPROM I2C Address

#define ClockSpeed              200000 // 200 KHz

#include ''mainsee.h''

void I2Cmain(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

I2C_InitTypeDef  I2C_InitStructure;

       

  /* I2C1 and I2C2 Periph clock enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);

  /* GPIOB Periph clock enable */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

 

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

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10 | GPIO_Pin_11;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOB, GPIO_Pin_10, GPIO_AF_I2C2);

  GPIO_PinAFConfig(GPIOB, GPIO_Pin_11, GPIO_AF_I2C2);

  //I2C_DeInit(I2C2);    

           

  /* I2C2 configuration ------------------------------------------------------*/

  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;

  I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS7;

  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

  I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;

  I2C_Init(I2C2, &I2C_InitStructure);

  /* Enable I2C2 -------------------------------------------------------------*/

  I2C_Cmd(I2C2, ENABLE);

  /* Send I2C1 START condition */

  I2C_GenerateSTART(I2C2, ENABLE);

  /* Test on I2C1 EV5 and clear it */

 // while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));

   /* Send EEPROM slave Address for write */

  //I2C_Send7bitAddress(I2C2, I2C2_SLAVE_ADDRESS7, I2C_Direction_Transmitter);  }

  /* Test on I2C1 EV6 and clear it */

 // while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

 while(1){

  /* Send I2C1 EEPROM internal address */

  I2C_SendData(I2C2, 0x00);   }

  /* Test on I2C1 EV8 and clear it */

  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

  /* Send I2C1 EEPROM data */

  I2C_SendData(I2C2, 0x05);

  /* Test on I2C1 EV8 and clear it */

  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

  /* Send I2C1 STOP Condition */

  I2C_GenerateSTOP(I2C2, ENABLE);

  while(1); // Do not exit

}

Thank you very much in advance to help me.

P.S: Sorry for the english, i'm French.

This discussion is locked. Please start a new topic to ask your question.
20 REPLIES 20
Amel NASRI
ST Employee
Posted on January 07, 2015 at 09:31

Hello Siddharth,

This is an old thread. Please try to describe your problem in a separate discussion giving more details on your case. This will be easier to provide you help.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Announcement

We’re moving the ST Community to a new platform to give you a better and more reliable community experience.