Skip to main content
STAR
Associate III
September 30, 2020
Question

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.

  • September 30, 2020
  • 5 replies
  • 2244 views

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

This topic has been closed for replies.

5 replies

TDK
September 30, 2020

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
October 1, 2020

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

This is my steps to use "printf float"

STAR
STARAuthor
Associate III
October 1, 2020

I am using Atollic true studio,

STAR
STARAuthor
Associate III
October 1, 2020

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

STAR
STARAuthor
Associate III
October 1, 2020

required settings in atollic true studio.