cancel
Showing results for 
Search instead for 
Did you mean: 

Transmission problem Using of IDLE Line Flag in STM32F4 UART

vinayakrjoshi
Associate II
Posted on July 17, 2015 at 06:00

HI,

I am using IDLE Flag to check the IDLE Bus condition in my UART Transmit routine.

void serialOut(uint8_t Channel,uint8_t *data,uint8_t len)

{

     uint8_t is_Rx_line_Idle=0;

     is_Rx_line_Idle = __HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE);

    

    //len= strlen((char *)data);

    /* send the packet when Data is present in buffer and any ongoing Reception is complete */

    if ((0 != len) && (data != (void*)0)&&(is_Rx_line_Idle))// && (RxCount[Channel] == 0))

    {        

         if (UART_A == Channel )

         {

            

                HAL_UART_Transmit_IT(&huart1,(uint8_t *)data,len);

         }

        

         if (UART_B == Channel )

         {

                HAL_UART_Transmit_IT(&huart6,(uint8_t *)data, len);

                //HAL_UART_Transmit_IT(&huart2,(uint8_t *)data, len);

         }

    }

}

The interesting thing i am facing is like, UART is not transmitting any byte. I am sending dummy byte @500 msec rate. But i send any byte to my UART everything working fine. that means UART start sending bytes at specified intervals.

Why the first time UART is not sending the Data? why the IDLE line not set to 1 initially?

Pl. help me to understand what the significance of IDLE flag and what is the good practices to use that? and when?

Thanks

Vinayak

#uart-sending-problem-on-stm32f4
1 REPLY 1
jpeacock
Associate III
Posted on July 17, 2015 at 14:22

The IDLE is edge triggered and has to see an RXNE from an incoming byte before it can detect an idle line.  You have to receive a character before the line becomes idle.  The idea behind this is message framing: do an RXNE interrupt for the first byte of an incoming message, start the RX DMA for the rest of the message, and terminate DMA with an IDLE event.

IDLE works with RX, not TX so it isn't related to what the USART sends.

IDLE is useful in framing messages, such as RTU mode in the MODBUS protocol where an end of message is signaled by a gap in receiving characters.  In practice IDLE isn't that useful on the F4 because of the short time for idle detect, but in theory if you are running a message protocol where incoming data has no gaps between characters then the IDLE interrupt is the end of frame event that terminates an RX DMA.

There are some other M4 controllers that have a programmable IDLE timer, which makes this feature far more useful.  A workaround on the F4 is to connect the incoming RX data line to a timer input pin (I use TIM9) and detect a longer idle period that way.

  Jack Peacock