cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_Irda problem : ping-pong communication fails

Mathieu Garivet
Associate III
Posted on April 21, 2017 at 12:03

Hi everyone,

I'm developing a firmware in which a IR communication protocol is designed. The uC is a STM32F042C6 and I'm using HAL drivers.

The protocol should work as follow (infinite loop):

1> Receive 1 byte in interrupt mode ;

2> Wait 10ms (in order to assure a delay of 10ms between Rx and Tx as recommanded by the IRDA standard ;

3> Transmit the same 1 byte in interrupt mode.

4> Wait 10 ms ;

1> ...

Materials :

PC Teraterm console <=cable link full duplex=> (Nucleo board + IRDA module) <=IR link half duplex=> (STM32F042 + IRDA module)

The first step works fine: I'm sending character from another board connected to my PC via a Teraterm console. Using debug Breakpoint, I see that the character is correctly received. However step 3 doesn't work fine. Something is sent but in the console I get only awkward characters that have nothing to do with the expected one.

The funny (but really annoying) part of story is that the transmission works fine when I just sent periodically characters to the PC : all characters are received correctly.

So I'm wondering why the switch between Rx and Tx steps does not work. Could this have something to do with the half-duplex propriety of the IRDA link ?

Code samples :

This works fine (does not work without the delays) :

c = 'h';

HAL_IRDA_Transmit(&hirda1, &c, 1, 10);HAL_Delay(10);

c = 'e';

HAL_IRDA_Transmit(&hirda1, &c, 1, 10);HAL_Delay(10);

c = 'l';

HAL_IRDA_Transmit(&hirda1, &c, 1, 10);HAL_Delay(10);

c = 'l';

HAL_IRDA_Transmit(&hirda1, &c, 1, 10);HAL_Delay(10);

c = 'o';

HAL_IRDA_Transmit(&hirda1, &c, 1, 10);HAL_Delay(10);

This does not work (c is correctly received but transmission not)

while (1)

{

   HAL_StatusTypeDef status = HAL_IRDA_Receive(&hirda1, &c, 1, 1000);

   if(status == HAL_OK){

      HAL_Delay(100);

      HAL_IRDA_Transmit(&hirda1, &c, 1, 10);

      HAL_Delay(10);

   }

}

Any idea ? Something i'm doing wrong ?

Thank you for your help.

#stm32-f0 #irda
2 REPLIES 2
selçuk Yolcu
Associate II
Posted on March 22, 2018 at 07:09

Same problem with me. I am using Interrupt to receive data and when 6th character is taken, I transmit data. But with second cycle, the received data is crashed by somethings. If receive data is used alone without transmit, then there is no problem, However, while either receive and transmit functions are used,  the received data became unreasonable. I use HAL functions, too.   If you solve it, please share with me.

Pierre Drouot
Associate
Posted on July 03, 2018 at 11:10

Hi, I have the same problem using dma on IrDA (STM32F091). I solved it doing a init of the usart just after TxCplt (using the callback).

Did you try to print on a console the registers of he USART ? When i did it i found that 3 bits in the ISR register were set : RXNE, CMF and FE. The same print after the init reset these bits.

The second thing i tried was to disable the Rx (RE bit in CR1) during the transmit and set it back but it didn't solved the problem. So the only way i found to solve it is to do the init after each transmit.