cancel
Showing results for 
Search instead for 
Did you mean: 

Irda communication stopps working after sending too many bytes

FImfe
Associate

Hi There,

I use a Stm32l072 (to be exactly, the CMWX1ZZABZ Lora module) with a infrared receiver. The Protocol is Irda Sir with the following specs:

  • 1152000 Baud
  • 8 Bit Data
  • No Parity

To test it, i wrote a simple CubeMx programm that receives correct data once:

// MAIN
// ...
// other init stuff here
 
  hirda1.Instance = USART1;
  hirda1.Init.BaudRate = 115200;
  hirda1.Init.WordLength = IRDA_WORDLENGTH_8B;
  hirda1.Init.Parity = IRDA_PARITY_NONE;
  hirda1.Init.Mode = IRDA_MODE_TX_RX;
  hirda1.Init.Prescaler = 1;
  hirda1.Init.PowerMode = IRDA_POWERMODE_NORMAL;
  if (HAL_IRDA_Init(&hirda1) != HAL_OK)
  {
    Error_Handler();
  }
 
  __HAL_IRDA_ENABLE(&hirda1);
 
 while (1)
  {
	HAL_StatusTypeDef rc;
	uint8_t irdaBuffer[200] = {0};
 
	rc =  HAL_IRDA_Receive(&hirda1,irdaBuffer,3,1000*5);
 
	if(rc==HAL_OK)
	{
		  HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_SET);
	}
	else
	{
		  HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_RESET);
	}
  }

The problem:

When sending 3Bytes over Irda, it works fine. When sending >3Byte, the first three are correctly received but the following do never appear and the "HAL_IRDA_Receive" wont work anymore. I would assume i should receive the following Bytes as soon as i call "HAL_IRDA_Receive" again, until the Rx buffer is empty? Or did i miss a step? With the DMA it shows the same behavior.

Thanks for help

3 REPLIES 3
Ozone
Lead

> rc = HAL_IRDA_Receive(&hirda1,irdaBuffer,3,1000*5);

I use to not dabble in Cube stuff, but this looks like you pass a buffer size of 3, which would explain the "magic" limit.

What happens if you send less ?

What happens in the HAL code after the 3 bytes are received ?

I think you need reflect upon your requirements and your application.

Are data transmitted in equally sized packages, and regularly ? Or sporadically, with unknown size ?

That would define the method that works best for you (DMA, interrupt).

FImfe
Associate

Thank you for your fast reply,

The size of 3 is just a random value to show the limitation, i can insert "siezeof(buffer)" and i have the same problem (HAL_IRDA_Receive

not working anymore) when i transmitt more data than the buffer size. Obviously this is not a usefull implementation, its just to show my the problem.

"What happens if you send less ?"

-> The function hits its timeout as it should"

"What happens in the HAL code after the 3 bytes are received ?"

-> when only 3Bytes are sent (per loop) the code works correct

-> when more than 3Bytes are sent in one loop, the HAL function receives the first 3 and in the following loops it wil allways timeout. It timeouts as well, when i send new bytes. So im not able to receive anything again.

My data is transmitted randomly in diffrent sizes. I will later use the DMA and delimiters in my data, but at first the basic rx-path should work correctly.

I don't intend to debug Cube either, but I'd guess the UART Rx overflows and the overflow prevents further Rx.

Read the UART chapter in RM and debug the Cube code accordingly.

JW