cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Slave Address Set Problem

Omerbzkt
Associate II

I'm trying to read data from my I2C sensor, the MLX90614 sensor, using a STM32F411CEU6. When I examined the MLX90614 datasheet, I saw that the I2C clock speed should be a maximum of 100kHz and I configured the clock accordingly. However, after the start condition is set, although I write the slave address to the I2C_DR register, I cannot get the address set flag. I leave the code I wrote below. Thank you if you help. Enjoy your work.

3 REPLIES 3
Omerbzkt
Associate II

Duplicate - merged.


I'm trying to read data from my I2C sensor, the MLX90614 sensor, using a STM32F411CEU6. When I examined the MLX90614 datasheet, I saw that the I2C clock speed should be a maximum of 100kHz and I configured the clock accordingly. However, after the start condition is set, although I write the slave address to the I2C_DR register, I cannot get the address set flag. I leave the code I wrote below. Thank you if you help. Enjoy your work.

padawan
Senior II

Hi,

The code is difficult to read. Why don't you use the HAL_functions for the first tests?
About the hardware: 1st question are the pullups available? The internal pullup of the ports is not sufficient. (should be about 3k3).
The Melexis sends 3 bytes when reading.

i have a little different sensor (MLX90615)

 

 

I2C_HandleTypeDef *_i2c = &hi2c1;// your i2c port
uint8_t _adr = 0xB4;
uint8_t _ret =0xFF;
_ret= (HAL_I2C_IsDeviceReady(_i2c,_adr,3,200) == HAL_OK);

 

Code as example, not testet.

 

int16_t	mlx90615::getID(uint8_t addr)
{


	uint16_t _ret= 0xFFFF;
	uint8_t _rbuff[5]={0,0,0,0,0};
	uint8_t _sbuff = 0x1C; // MLX_regID1
	HAL_StatusTypeDef _Hal;

	_Hal=(HAL_I2C_Mem_Read (_i2c, addr, _sbuff ,I2C_MEMADD_SIZE_8BIT,_rbuff,5,100));
		if  (_Hal==HAL_OK)
			{
			_ret = ((_rbuff[1]<<8)& (_rbuff[0]));
			}

		return _ret;

}

 

May be this helps.

padawan

May be you can try with HAL libraries to program, so that the error detection is easier. Once logic is fully established you can test your register based prigramming. 

If you feel a post has answered your question, please click "Accept as Solution".