2023-05-12 04:04 AM
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);
2023-05-13 08:33 AM
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.
2023-05-13 09:14 AM
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.
2023-05-15 01:03 AM
Hello S.Ma and Piranha
Thnaks for your suggestions and help.
Sincerely
2023-05-15 08:02 AM
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