This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help with float variable and UART transmission

Hi everyone

I'm having trouble reading the right values from the uart using a serial port logger.

I'm using the cygnal C8051F124 uc and I send in four bytes a float variable by the UART0

To convert the flot variable in 4 bytes I have the following code:

union {

float floater;
unsigned long int longinter;
unsigned char string[4];
unsigned int interger[2];
}float_char;

To convert I use:

float_char.floater=0.43567;
sendbuff[0]=float_char.string[0];
sendbuff[1]=float_char.string[1];
sendbuff[2]=float_char.string[2];
sendbuff[3]=float_char.string[3];



Then If I sent the same value stored in sendbuff[x] everytime I send the data by the UART0 I get the exact value without errors.

That means maybe the conversion from float to 4 bytes is incorrect or maybe cause some problems.

I think the UART tranmission is correct because if I dont change the value in the sendbuff[i] variables I obtained in the pc the values that I want.

Please give me suggestions

Thanks

0