2024-06-06 5:48 AM
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.
2024-05-30 2:14 PM - last edited on 2025-06-13 7:54 AM by Andrew Neil
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.
2024-06-06 7:27 AM - edited 2024-06-06 7:33 AM
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
2024-06-24 6:45 PM
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.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.