cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 and I2C problem

nikola
Associate
Posted on February 08, 2015 at 17:14

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 I am using pull up resistor of 10k. Does someone know what may be a problem?


uint8_t I2C_address;

uint32_t I2C_speed;


GPIO_InitTypeDef GPIO_InitStructure;

I2C_InitTypeDef I2C_InitStructure;


I2C_address = 0x5A<<1; 
//

I2C_speed = 100000; 
// 1000Hz


/* I2C1 clock enable */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);


/* I2C1 SDA and SCL configuration */

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);

//SCL is pin06 and SDA is pin 07 for I2C1


/* I2C1 configuration */

I2C_InitStructure.I2C_Mode = I2C_Mode_SMBusHost;

I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;

I2C_InitStructure.I2C_OwnAddress1 = 0x00;

I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

I2C_InitStructure.I2C_ClockSpeed = I2C_speed ;

I2C_Init(I2C1, &I2C_InitStructure);


I2C_Cmd(I2C1,ENABLE);


I2C_AcknowledgeConfig(I2C1, ENABLE);

/* Test on BUSY Flag */

while
(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY));

/* Enable the I2C peripheral */


/*======================================================*/

I2C_GenerateSTART(I2C1, ENABLE);

/* Test on start flag */

while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));


/* Send device address for write */

I2C_Send7bitAddress(I2C1, I2C_address, I2C_Direction_Transmitter);

/* Test on master Flag */

while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));


/* Send the device's internal address to write to */

I2C_SendData(I2C1,0x07);

/* Test on TXE FLag (data sent) */

while
(!I2C_GetFlagStatus(I2C1,I2C_FLAG_TXE));

0 REPLIES 0