cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_Delay and UART problem.

Francesco_
Associate II
Posted on July 06, 2018 at 14:09

I have a problem with stm32f103, if insert in HAL_Delay(1000) in Serial Monitor i see incorrect results, but if i insert HAL_Delay(150) the results are correct. I do not understand why!

This is the code:

while (1)

{

HAL_ADC_Start(&hadc1);

if(HAL_ADC_PollForConversion(&hadc1,10) == HAL_OK){

sensorVal = HAL_ADC_GetValue(&hadc1);

HAL_ADC_Stop(&hadc1);

}

VSENSE = sensorVal*ADC_TO_VOLT;

temperature = (V25 - VSENSE) / AVG_SLOPE + 25;

char buffer[7];

sprintf(buffer, '%5.2f\n', temperature); 

HAL_GPIO_WritePin(LED13_GPIO_Port, LED13_Pin, GPIO_PIN_SET);

HAL_UART_Transmit(&huart1, (uint8_t*)buffer, sizeof(buffer) ,HAL_MAX_DELAY);

HAL_GPIO_WritePin(LED13_GPIO_Port, LED13_Pin, GPIO_PIN_RESET);

HAL_Delay(150);

}

2 REPLIES 2
Posted on July 06, 2018 at 14:36

>>i see incorrect results

That's not exactly helpful to those not observing it directly.

>>I do not understand why!

Not exactly sure either, some chance you can post a more complete compilable code that illustrates?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 06, 2018 at 17:30

If i use HAL_Delay(1000) the Serial Monitor show numeric value of temperature incorrect.