cancel
Showing results for 
Search instead for 
Did you mean: 

My ADC working but not able to sent float value on UART. Only integer its working fine. But when I sent float value using sprintf function then it sent only zeros.

STAR
Associate II

My code is below,

uint16_t val;

float voltage=0;

while

{

    HAL_Delay(1000);

        /* USER CODE END WHILE */

          HAL_ADC_Start(&hadc);

          HAL_ADC_PollForConversion(&hadc, 10);

  val = HAL_ADC_GetValue(&hadc);

 

     voltage= ((val/4096)*3.3);

       sprintf(p,"%1.3f ",voltage); /* For floting value displaying*/  

          HAL_UART_Transmit(&huart2, p, sizeof(p), 10);

          HAL_ADC_Stop(&hadc);

}

but when I sent the integer value its work proprly like, please refer below code

while

{

HAL_Delay(1000);

        /* USER CODE END WHILE */

         HAL_ADC_Start(&hadc);

   HAL_ADC_PollForConversion(&hadc, 10);

 val = HAL_ADC_GetValue(&hadc);

sprintf(p, "%d ", val);

HAL_UART_Transmit(&huart2, p, sizeof(p), 10);

   HAL_ADC_Stop(&hadc);

}

I have set the linker  -u _printf_float in command and -mfloat-abi=soft in Compiler

but not got success yet. please

5 REPLIES 5
TDK
Guru

I don't think "Additional object files" is the appropriate place for those options. STM32CubeIDE has a checkbox to enable these in "MCU Settings".

If you feel a post has answered your question, please click "Accept as Solution".
RZHU.1
Associate III

project->properities->C/C++build->Settings->MCU settings->use float......

This is my steps to use "printf float"

I am using Atollic true studio,

STAR
Associate II

  not able to find -mfloat-abi=soft  settings in atollic true studio

STAR
Associate II

required settings in atollic true studio.