alejoseb / Modbus-STM32-HAL-FreeRTOS

Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS
GNU Lesser General Public License v2.1
579 stars 192 forks source link

Can't get any interrupt when receive frame #48

Closed buch2001 closed 2 years ago

buch2001 commented 2 years ago

Hi,

i've this strange behaviour and I can't figure it out why.

I've already used this library before and so I can't understand why I've so many trouble now, but basically I can't receive any interrupt when receiving a Modbus frame from the master.

I've configured my device as a slave with the following parameters:

/* Modbus Slave initialization */
modH->uModbusType = MB_SLAVE;
modH->port =  &huart3; // This is the UART port connected to STLINK in the discovery F429
modH->u8id = 1; //Master ID
modH->u16timeOut = 1000;
modH->EN_Port = UART3_TX_EN_GPIO_Port; // RS485 Enable
modH->EN_Pin = UART3_TX_EN_Pin; // RS485 Enable
modH->u16regs = ModbusDATARX;
modH->u16regsize= sizeof(ModbusDATARX)/sizeof(ModbusDATARX[0]);
modH->xTypeHW = USART_HW;

My GPIOs are set in this way:

GPIO_InitStruct.Pin = UART3_TX_EN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

GPIO_InitStruct.Pin = UART3_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART3;
HAL_GPIO_Init(UART3_RX_GPIO_Port, &GPIO_InitStruct);

GPIO_InitStruct.Pin = UART3_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_UART3;
HAL_GPIO_Init(UART3_TX_GPIO_Port, &GPIO_InitStruct);

And the interrupt is this way:

/* UART3 interrupt Init */
HAL_NVIC_SetPriority(UART3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(UART3_IRQn);

And the uart is set in this way:

static void MX_UART3_Init(void)
{

  /* USER CODE BEGIN UART3_Init 0 */

  /* USER CODE END UART3_Init 0 */

  /* USER CODE BEGIN UART3_Init 1 */

  /* USER CODE END UART3_Init 1 */
  huart3.Instance = UART3;
  huart3.Init.BaudRate = 38400;
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
  huart3.Init.StopBits = UART_STOPBITS_1;
  huart3.Init.Parity = UART_PARITY_NONE;
  huart3.Init.Mode = UART_MODE_TX_RX;
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart3) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN UART3_Init 2 */

  /* USER CODE END UART3_Init 2 */

}

I'm putting a brekpoint here when I send messages though QModBus tool but it's never reached

void UART3_IRQHandler(void)
{
  /* USER CODE BEGIN UART3_IRQn 0 */

  /* USER CODE END UART3_IRQn 0 */
  HAL_UART_IRQHandler(&huart3);
  /* USER CODE BEGIN UART3_IRQn 1 */

  /* USER CODE END UART3_IRQn 1 */
}

What I'm missing?

Thanks in advance for any help

alejoseb commented 2 years ago

Hi, the setup seems right. The issue is quite general and not related to the library, at all. Besides that, you should test the serial port interrupt even before adding the library. Also check the RTOS is running.