cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UARTEx_ReceiveToIdle_DMA() and LIN

userembedded
Associate

Hi,

 

I am working on STM32F1 family and implementing LIN communication. I found the function HAL_UARTEx_ReceiveToIdle_DMA() that is very useful to handle variable incoming data.

 

But I have a problem that this function only works first time, but not calling HAL_UARTEx_RxEventCallback(), I need to get data in USART1_IRQHandler() function. The reason is because the flag of Frame Error is arrising and stops the receive DMA process. The intersting is that the received data is correct, for all different RX size.

 

I review all init and functions according to the examples and forum, and it seems ok.  Could it be because the link break detection? My RX buffer always show zero as the first byte, so it compute the break as first data.

byte[0] = break;

byte[1] = sync;

byte[2] = PID...

 

st forum.png

DMA init

 

static void MX_DMA_Init(void)
{

  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  /* DMA1_Channel5_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);

}

 

Start receive process:

 

  if (HAL_OK != HAL_UARTEx_ReceiveToIdle_DMA(&huart1, pdata, 20))
  {
	  Error_Handler();

  }

 

Lin Config:

lin init.png

 

DMA config:

lin init 2.png

 

 

 

 

2 REPLIES 2
TDK
Guru

If frame error bit is set, there's probably a frame error in the data.

Perhaps the line is not properly pulled up prior to initialization. Can you view the signal on a scope? What is sending the signal?

If you feel a post has answered your question, please click "Accept as Solution".

Hi,

 

Thanks for the fast reply. yes the signals are ok in a scope. The sender is a proper LIN transmitter.

 

Now I could make it works with HAL_UARTEx_ReceiveToIdle_IT(), it receives correctly and call HAL_UARTEx_RxEventCallback() with correct number of received bytes. For while I will use interruption instead of DMA.