/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / STM32 Discovery I2C

Username:     
Password:     
             

Forum

# 1   2012-05-04 09:10:25 STM32 Discovery I2C

lolive03
New member
Registered: 2012-05-04
Posts: 1

STM32 Discovery I2C

Hello everbody!
I work with an STM32L and in eed to communicate with EEPROM in I2C(M24C64 or m24lr64, the result are the same).
But i've some problem to have good result with:
my code:

  GPIO_InitTypeDef GPIO_InitStructure;
  I2C_InitTypeDef I2C_InitStructure;

   /* Enable I2C clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);

    /* Enable GPIOA clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  /* Configure PB.10 & PB.11 in alternate function -------------------------*/
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_I2C2) ;
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_I2C2) ;

  /* Enable I2C2 -------------------------------------------------------------*/
  I2C_DeInit(I2C2);    
  I2C_Cmd(I2C2, ENABLE);

     /* Init I2C */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_ClockSpeed = 400000;  //IS_I2C_CLOCK_SPEED(400000)
  I2C_InitStructure.I2C_AcknowledgedAddress=0xA0;
  I2C_Init(I2C2,&I2C_InitStructure);

// I2C_GenerateSTART(I2C2, ENABLE);
   //Delay(1);
    I2C_AcknowledgeConfig(I2C2, ENABLE);   
   while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
   I2C_GenerateSTART(I2C2, ENABLE);
   while(!I2C_GetFlagStatus(I2C2, I2C_FLAG_SB));      
   while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
   I2C_Send7bitAddress(I2C2,0xA0,I2C_Direction_Transmitter); Delay(17);
//  while(!I2C_CheckEvent(I2C2,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); 
       /* adresse */
   I2C_SendData(I2C2,0x07);Delay(17);// Send Year register address
   I2C_SendData(I2C2,0x40);Delay(17);
//   while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTING));

      

   I2C_GenerateSTOP(I2C2, ENABLE);
   //Delay(20);

Some while are in comment because if i se it the programm block in this while.
and i joined a result in oscilloscope:
http://image.noelshack.com/minis/2012/18/1336122492-tek00000.png
The ack are little bit strange and i don't know why.
So if you see error in my code tell me.
Thank you

Offline

 

# 2   2012-05-10 07:44:04 STM32 Discovery I2C

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: STM32 Discovery I2C

You can take a look to this project, as an example :
http://www.stm32circle.com/projects/project.php?id=102

Offline

 

Board footer