I read temperature, do calculations according to datasheet but get incorrect values. Tried different ways of calculations (separating values into different variables, changing types) but still no success.

here's part of datasheet:

here's macro of i2c reading of raw temperature

here are calculations according to datasheet

Code: Select all

`x1 = ((ut - ac6) * ac5) >> 15`

x2 = (mc << 11) / (x1 + md)

b5 = x1 + x2

t = (b5 + 8) >> 4

variable types are following:

ut, x1,x2,b5,t = long

ac5, ac6 = uint

mc, md = int

results in terminal are

Code: Select all

`ut=29358 t=434`

434 is incorrect, current temp is 27.5C so it must show 275 or around that.

434 is also changes time to time around 434, 438, etc as I open windows to change inside temp.. so seems like it reads the temperature and not some fixed data.

where I could be wrong? I suppose that the problem may be in calculations and types.

help me to locate the problem, please.

Thank you in advance.