Hello Guys,
I have a couple of TMP102 connected over i2c to my F28027 microcontroller. Everything works well. I also use the IQ math library (a brilliant thing btw). My sensors return temperature in fractional two's complement format therefore it is practically a Q number already. I store the read-out value (from i2c) in Uint16 and my function returns _iq format.
However, the data from TMP102 are 12b only. Treating (casting) them like _iq4 (or _iq8 depending on alignment) works only for positive numbers. For negative numbers I need to check the most significant bit (bit 11) and then modify the rest of bits in 32b variable (_iq number).
Long story short I need to set bits 31:12 to 1 if the bit 11 is negative.
Now comes the question:
What is the most elegant way to do that ?
Thanks in advance,
Jiri