2024-06-06 05: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-06-06 07:27 AM - edited 2024-06-06 07: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