Skip to main content
Visitor II
August 22, 2025
Solved

Mixing Polling Mode Modules with UART Interrupt Mode on STM32: Is It Safe?

  • August 22, 2025
  • 3 replies
  • 599 views

I'm developing a project using an STM32 Nucleo board. At the core of this project is a UART-based communication protocol running in interrupt (IT) mode — not polling or DMA. This protocol is responsible for controlling multiple subsystems such as a relay module and a fan speed controller.

However, most of these subsystem modules were previously written in polling mode.

My question is:
Can I integrate these polling-based modules into my current UART IT-mode communication system without causing issues? Or should I consider converting them to interrupt or DMA mode to prevent CPU blocking or communication delays?

Additionally:
What should I watch out for to ensure the CPU doesn't get blocked and UART interrupts don't get delayed in this mixed-mode setup?

Extra context:
There are 20 NTC temperature sensors in the system, and temperature from all of them is read once every second using ADC. The highest temperature value is selected and stored in a variable. Based on this value, the fan speed is adjusted accordingly.

Note: The polling-based modules do not contain any infinite loops like while(1) or other blocking code. For example, the ntc reader and fan control logic looks like:

 

 

NTC_Read_Temperatures(temps);
HAL_Delay(1000);


if(max_temp == 54.23f ){
speed_of_fan = mode_2;
hal_delay(1);
}

    This topic has been closed for replies.
    Best answer by durna

    I solved

    I should use like this code;


    if (HAL_GetTick() - lastTempReadTime >= 1000)
    {
    lastTempReadTime = HAL_GetTick();
    NTC_Read_Temperatures(temperatures);

    if (!FanControl_GetManualMode())
    {
    float maxTemp = NTC_GetMaxTemperature();
    FanControl_Update(maxTemp);
    }
    }

    3 replies

    Graduate
    August 22, 2025

    At first look, I would suggest move UART to DMA and keep all program as it is.

    Polling DMA result at intervals, allow to detect what happened on UART without disturbing other functions.

    Remember that DMA must be stopped on error or timeout.

    mike

    durnaAuthor
    Visitor II
    August 22, 2025

    Thank you. Yes, moving the communication module to DMA would at least ensure its functionality. But what would happen if I left it in IT mode as it is now? What potential dangers would there be in this case?

    Graduate
    August 22, 2025

    If you are playing only TX, no problems, but with RX you will need to manage rx buffer before oveflowing - you already bought a device with DMA, use it,it is free, and you will be much more reliable.

    Super User
    August 22, 2025

    Can I integrate these polling-based modules into my current UART IT-mode communication system without causing issues?

    Of course you can. This can be done with intermediate buffer between the polling stuff and interrupt driven routines.

    The latter will store bytes in a ring buffer (or whatever), then the polling read function will fetch from the buffer. Same for DMA.

    If you are new to STM32 and need help with coding, help is available here.

     

     

     

    durnaAuthorAnswer
    Visitor II
    August 26, 2025

    I solved

    I should use like this code;


    if (HAL_GetTick() - lastTempReadTime >= 1000)
    {
    lastTempReadTime = HAL_GetTick();
    NTC_Read_Temperatures(temperatures);

    if (!FanControl_GetManualMode())
    {
    float maxTemp = NTC_GetMaxTemperature();
    FanControl_Update(maxTemp);
    }
    }