AnsweredAssumed Answered

STM32 and I2C problem

Question asked by Nixte on Feb 8, 2015
Hi,

I have STM32VLDISCOVERY that needs to read temperature from MLX90614 over I2C bus.

Here is part of code I am using to read registers and it never pass line 45. I am using pull up resistor of 10k. Does someone know what may be a problem?
01.uint8_t I2C_address;
02.  uint32_t I2C_speed;
03.   
04.  GPIO_InitTypeDef    GPIO_InitStructure;
05.  I2C_InitTypeDef     I2C_InitStructure;
06.   
07.  I2C_address = 0x5A<<1; //
08.  I2C_speed = 100000;   // 1000Hz
09.   
10.  /* I2C1 clock enable */
11.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
12.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
13.   
14.  /* I2C1 SDA and SCL configuration */
15.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
16.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
17.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
18.  GPIO_Init(GPIOB, &GPIO_InitStructure);
19.  //SCL is pin06 and SDA is pin 07 for I2C1
20.   
21.  /* I2C1 configuration */
22.  I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;
23.  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
24.  I2C_InitStructure.I2C_OwnAddress1 = 0x00;
25.  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
26.  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
27.  I2C_InitStructure.I2C_ClockSpeed = I2C_speed ;
28.  I2C_Init(I2C1, &I2C_InitStructure);
29.   
30.  I2C_Cmd(I2C1,ENABLE);
31.   
32.  I2C_AcknowledgeConfig(I2C1, ENABLE);
33.  /* Test on BUSY Flag */
34.  while (I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY));
35.  /* Enable the I2C peripheral */
36. 
37.  /*======================================================*/
38.  I2C_GenerateSTART(I2C1, ENABLE);
39.  /* Test on start flag */
40.  while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
41.   
42./* Send device address for write */
43.  I2C_Send7bitAddress(I2C1, I2C_address, I2C_Direction_Transmitter);
44.  /* Test on master Flag */
45.  while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
46.   
47.  /* Send the device's internal address to write to */
48.  I2C_SendData(I2C1,0x07);
49.  /* Test on TXE FLag (data sent) */
50.  while (!I2C_GetFlagStatus(I2C1,I2C_FLAG_TXE));

Outcomes