cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 HAL_UART_Receive_DMA shifting every cycle

YAlie.1
Associate

Hello everybody:

i'm trying to implement modbus function on mcu(stm32F4)

my structure as following

0693W000007DhYjQAK.png

i receive data from usart6 by HAL_UART_Receive_DMA function(circular mode)

it's work when just only one MCU edge. but if two mcu edge (two modbus slave), it will make some problem.

when i polling the mcu1 only, the rxbuffer from DMA is correctly(modbus-rtu query package)

0693W000007DhZhQAK.png

when i pooling mcu1(slaveID 2) and mcu2(slaveID 4), the package will be shift or incorrect.

0693W000007DhaBQAS.png0693W000007DhaLQAS.png0693W000007DhaQQAS.png 

my DMA parameter

0693W000007DhafQAC.png0693W000007DhaCQAS.png 

my question is

i reveice uart data by "HAL_UART_Receive_DMA"

how to fix the rxbuffer shifting issue

i 'm sure that the modbusPoll(master) send the correct package

0693W000007DhbEQAS.png

/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 /* Prevent unused argument(s) compilation warning */
	UNUSED(huart);
 /* NOTE: This function should not be modified, when the callback is needed,
          the HAL_UART_RxCpltCallback could be implemented in the user file
  */
	__NOP();
	if(huart==&huart6)
	{
		if (rxbuffer[0]==slaveID)
			{
				/* if slaveID match
				 * put rxbuffer to ModBusInHandle
				 */
				__NOP();
				for(int i=0;i<8;i++)
					osMessagePut(ModBusInHandle,rxbuffer[i], 8);
			}
			else
			{
				// if uart RX_ID no match slaveID(switch on board), reset rxbuffer
				memset(rxbuffer,0, 8);
			}
		HAL_Delay(1);
	}
 
 
	// active DMA again, because DMA set normal mode
	//HAL_UART_Receive_DMA(&huart6, rxbuffer, 8);
 
}

1 REPLY 1

Sounds like a similar problem to this. Try to do what I've recommended there. Maybe the ISR is too slow or some other ISR blocks it for too long so that data are missing.

JW