I'm using a Raspberry Pi 2B to get data from a custom made PCB using the serial peripheral. I wrote the code in C using Geany. The serial frame I'm receiving on the Pi is simple; 8 bytes, 2 sets of 16 bit integers and the remaining 4 bytes being a single precision floating variable. The issue is with the floating variable. Below is the way I'm constructing the floating value (and other 16bit integers) from the bytes received.
Code: Select all
tmp = (rx_buff << 8); tmp |= (rx_buff); mtr_v[cnt] = (double)tmp/1000; tmp = (rx_buff << 8); tmp |= (rx_buff); mtr_c[cnt] = (double)tmp/10000; p = (uint8_t *)&w_tmp; *p++ = (rx_buff); *p++ |= (rx_buff); *p++ |= (rx_buff); *p |= (rx_buff); mtr_w[cnt] = (double)w_tmp; mtr_w[cnt] *=(-1);
Any one has an idea about the reason?
Note: I don't know if it matters but I am receiving the 8 bytes continuously every 10ms.