Tool/software: Code Composer Studio
Hi.I am working on a CAN Bus project and I cant seem to print the floating value after performing a division operation between 2 unsigned 16 bit numbers. The value is printed as "ERROR2f":
Attached the code snippet for only the Print section:
uint8_t PPGMsg[5];
float PPG;
uint16_t IR_combined,RED_combined;
for(uIdx = 0; uIdx < psCANMsg->ui32MsgLen; uIdx++)
{
PPGMsg[uIdx]=psCANMsg->pui8MsgData[uIdx];
}
IR_combined = (PPGMsg[1]<< 8)|PPGMsg[2];
RED_combined = (PPGMsg[3]<< 8)|PPGMsg[4];
if(RED_combined==0)
PPGMsg[0]=0;
else
PPGMsg[0]=(RED_combined/IR_combined);
PPG=((float)RED_combined/(float)IR_combined);
UARTprintf("IR_combined is: %d\n",IR_combined);
UARTprintf("RED_combined is: %d\n",RED_combined);
UARTprintf("PPG is: %d\n",PPGMsg[0]);
UARTprintf("float PPG 1 is: %.2f\n",PPG);
UARTprintf("done\n");
