dasarathan
Newbie level 5
hi guys
im using ccs c complier PCH 16 bit
im reading the float data from modbus rtu as the array of byte and i convert the bytes to int32
while im type casting the int32 to float the result is 0.00
im using ccs c complier PCH 16 bit
im reading the float data from modbus rtu as the array of byte and i convert the bytes to int32
while im type casting the int32 to float the result is 0.00
Code:
float ModbusGetdata(int8 in_ValueReg)
{
int8 Readcount = 0;
int8 ReadBuffer[15] = {0};
float32 fretval = 0.0;
// int8 Timeoutcount =0;
uart_flush_buffer();
DOP_RX_EN(1);
delay_ms(5);
fputc(0x01,RS485TX);
fputc(0x03,RS485TX);
fputc(0x00,RS485TX);
fputc(PanelMeterCrc[in_ValueReg][0],RS485TX);
fputc(0x00,RS485TX);
fputc(0x02,RS485TX);
fputc(PanelMeterCrc[in_ValueReg][1],RS485TX);
fputc(PanelMeterCrc[in_ValueReg][2],RS485TX);
//! for(int LoopCnt = 0; LoopCnt < 8; LoopCnt++)
//! {
//! fputc(panelMeterPkt[in_ValueReg][LoopCnt],RS485TX);
//! }
//! UART_Write(0x0A);
delay_ms(2);
DOP_RX_EN(0);
delay_ms(500);
if(uart_available())
{
while(uart_available())
{
ReadBuffer[Readcount++] = uart_read(); //clear buffer
}
}
unsigned int32 retdata = convert32(ReadBuffer[3],ReadBuffer[4],ReadBuffer[5],ReadBuffer[6]);
lcd_clear_line(2);
printf(lcd_putc, "R:0x%LX",retdata);
fretval =(*(Float *)&retdata);
//memcpy(&fretval,&retdata,4);
//! fretval = *(float *) &retdata;
lcd_clear_line(1);
printf(lcd_putc, "R:%f",fretval);
return fretval ;
}
Last edited by a moderator: