OK I think I have the pointer figured out but the function does not return the expected value. I am not sure that the union is defined properly since I did change some on the data types to Arduino types. Here is the code section and I am sending a float value of 12.5. The output is 048480 and I expected toCCS() to return 82480000 or possibly 00004882 (reverse order).
The IEEE 754 format is seeeeeee-efffffff-ffffffff-ffffffff and Microchip format eeeeeeee-sfffffff-ffffffff-ffffffff .
[/ byte * toCCS(float value) {
//This is a routine to convert from IEEE to CCS. The inverse of the above.
static union {
float value;
byte bytes[4];
unsigned int words[2];
unsigned long lword;
} block;
byte sign;
block.value=value;
sign=block.bytes[3] & 128;
block.words[1]=(block.words[1] & 0x7F) & ((block.words[1]<<1) & 0xFF00);
block.bytes[2]=(block.bytes[2] & 0x7F) | sign;
block.bytes[3]=block.bytes[0];
block.bytes[0]=block.bytes[3];
block.bytes[1]=block.bytes[2];
block.bytes[2]=block.bytes[1];
return &block.bytes[0];
}
void setup(){
Serial.begin(9600);
}
void loop(){
float ftTemp;
byte * b_pointer;
ftTemp=12.5;
b_pointer=toCCS(ftTemp);
Serial.print ("float - ");
Serial.print( (b_pointer[0]),HEX);
Serial.print( (b_pointer[1]),HEX);
Serial.print( (b_pointer[2]),HEX);
Serial.print( (b_pointer[3]),HEX);
Serial.println();
//Serial.write(b_pointer,4);
delay(2000);
}code]