AnsweredAssumed Answered

HAL_Irda problem : ping-pong communication fails

Question asked by Mathieu Garivet on Apr 21, 2017

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.

Outcomes