This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to convert type uint32_t to float??

Hi,
I try to read value of timer of STM32L152VD and convert it to float type. The way I use is first define the below union:

typedef union
{
        uint32_t timercount;
        float    flowtime;
}union_timercount;

union_timercount flow;


then use function below:

uint32_t TIM_GetCounter(TIM_TypeDef* TIMx)
{
  /* Check the parameters */
  assert_param(IS_TIM_ALL_PERIPH(TIMx));

  /* Get the Counter Register value */
  return TIMx->CNT;
}


I send it to serial port:

flow.timercount=TIM_GetCounter(TIM2);
sprintf(str1,"\r\nu=%u f=%f",flow.timercount,flow.flowtime);
uart_out_str(str1);

but what I read is:
u=2248 f=0.000000 why float value is not being converted?

Parents Reply Children