I tried the memcpy(); but somehow is not working well.
I changed my code a little bit, so now i´m not saving the data values directly in the float variable, but in a byte Array.
const size_t floatSize = sizeof(float);
uint8_t bytes[floatSize];
.
.
.
void loop()
{
can_message_t rx_frame;
if(can_receive(&rx_frame,pdMS_TO_TICKS(1000))==ESP_OK)
{
printf("from 0x%08X,DLC%d,data", rx_frame.identifier,rx_frame.data_length_code);
for(int i=0;i<rx_frame.data_length_code;i++)
{
printf(" 0x%02X",rx_frame.data[i]);
}
printf(" Bytes values: ");
for (int i=3; i>-1;i--)
{
bytes[i]=rx_frame.data[3-i];
}
printf(" 0x%02X 0x%02X 0x%02X 0x%02X ",bytes[0],bytes[1],bytes[2],bytes[3]);
//Lat_delta_distance= (rx_frame.data[3] << 24) + (rx_frame.data[2] << 16) + (rx_frame.data[1] << 8) + (rx_frame.data[0]);
memcpy(&Lat_delta_distance,bytes,floatSize);
printf("; lat_dist: 0x%08X ; ", Lat_delta_distance);
Serial.println(""); // linefeed
printf("\n ");
}
}
Output:
from 0x00000130,DLC8,data 0x00 0x00 0x0C 0x42 0x00 0x00 0x00 0x00
Bytes values: 0x42 0x0C 0x00 0x00 //here is the 35 saved on the Bytes array
; lat_dist: 0x37588400 ; // After memcpy is the value completly different
// not the same as in Bytes values: