I am reading a 8 different values from a chip (0.0 to 0.224 in 0.32 steps) every step is 0.125 in °C.
I am a beginner with programming. Where is the mistake in my code?
I found a solution with bit manipulation.
The code was supposed to convert 0 -> 0, 32 -> 125, 64 -> 250, ... 224 -> 875
The IC gives it out as 1 byte.
For example the 64 = 01000000 | 160 = 10100000
The funktion getKomma was able to do it in the end but the bit manipulation is much easier.
´´´´
int16_t var = to >>5;
int16_t tmp = var * 125;
The slave returns the values (0, 32, 64, 96, 128, 160, 192, 224).
The values I wanted are 0.125 for 32, 0.250 for 64, and +0.125 for the next one.
The IC put the 1 on the 3 hightest bit values (1110 0000).
I tought it would be an idea to convert each IC-Value with a funktion.
so seems you get eight bytes back from an unknown IC, in an unknown communication protocol which can take a limited number of values (0, 32, 64, 96, 128, 160, 192, 224)
If that is the case then for any value greater than zero the value returned could be divided by 32 and the result used to calculate the required output by means of multiplication or using it as a lookup to an array