I'm currently trying to send floats over USB. The PC has a Qt application running the following code
float x = 2.0;
memcpy(buffer.data() + 14, &x, sizeof x);
with the debuglog function i can clearly see the series of bytes passing through with the following order
.. 00 00 00 40 ..
which according to this site
http://www.scadacore.com/field-tools/programming-calculators/online-hex-converter/
is converted to 1073741824 in case of little endianess.
on my STM32 i can use the following code to then turn on LED4
uint32_t a = buffer[14] | (buffer[15] << 8) | (buffer[16] << 16) | (buffer[17] << 24);
if (a == 1073741824){
HAL_GPIO_WritePin(LED4_PORT, LED4_PIN, GPIO_PIN_RESET);
}
The problem arises when i want to convert to the real float value 2.0
in fact if i do
float b = buffer[14] | (buffer[15] << 8) | (buffer[16] << 16) | (buffer[17] << 24);
if (b == 2.0f){
HAL_GPIO_WritePin(LED5_PORT, LED5_PIN, GPIO_PIN_RESET);
}
the LED5 is not turning on.
Is it an endianess problem? How can i obtain the float value 2.0?
Regards,