cancel
Showing results for 
Search instead for 
Did you mean: 

Interfacing MLX90614 sensor i2c with STM32F401 Discovery board. Problem : I am getting device address, register address, data address correct, but getting always NACK in stop condition. Can anyone please help me, this is my code snippet.

APand.7
Associate II

uint8_t I2C_ADDRESS = 0x00;

I2C_HandleTypeDef hi2c1;

int main(void){

HAL_StatusTypeDef status = HAL_ERROR;

uint8_t buf[3] = {0,};

uint32_t temp_data_a;

uint32_t temp_data_o;

__IO float T;

__IO float To;

while (1)

{

 HAL_I2C_Mem_Read(&hi2c1, 0x00, 0x06, I2C_MEMADD_SIZE_8BIT, buf, 2, 1000); // Read Ambient temperature from Register 0x06

 temp_data_a = buf[1]*256 + buf[0];

 HAL_I2C_Mem_Read(&hi2c1, 0x00, 0x07, I2C_MEMADD_SIZE_8BIT, buf, 2, 1000); // Read Object temperature from Register 0x07

 temp_data_o = buf[1]*256 + buf[0];

 To = temp_data_o*0.02;

 if(To >= 273.15)

  {

  To = To - 273.15;

  }

  else

  {

  To = -(273.15 - To);

  }

 T = temp_data_a*0.02;

if(T >= 273.15)

{

T = T - 273.15;

}

else

{

T = -(273.15 - T);

}

 HAL_Delay(500);

4 REPLIES 4
S.Ma
Principal

Melexis chip is bogus in the spec. The last data byte read by the master should be a NACK followed by a stop bit. The ACK/NACK is driven by the other party than the data sent just before.

However, this is the end of the I2C transaction the data has been transmitted anyway.

At least we know the datasheet unambiguously shows a non-true I2C protocol.

Piranha
Chief II

This topic is a duplicate, but we can see that ST doesn't punish "geniuses".

The datasheet is not bogus, look carefully:

A: Acknowledge (this bit can be 0 for ACK and 1 for NACK)

I've seen such a confusing abbreviation in documents of other manufacturers also. Don't know why they don't just use a letter N for NACK.

Also noticed this:

S: Start Condition
S: Stop Condition

While in diagrams a more logical P is used for STOP.

P.S. And generally documenting a generic protocols like I2C, RMII etc. in every part's datasheet is a pretty dumb trend anyway. Normally stating the generic standard and just providing a specific limits and differences should be enough.

APand.7
Associate II

Hello S.Ma and Piranha

Thnaks for your suggestions and help.

Sincerely

Lina DABASINSKAITE
Community manager
Community manager

Hello @APand.7​,

Thanks for participating in ST Community.

I have to close this thread because it is a duplicate. This is not in line with our community guidelines.

Please continue the discussion on the original post.

Best regards,

Lina - ST Community Team


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.