AnsweredAssumed Answered

RS485 Communication is not working properly

Question asked by Vaclav Chrascina on Dec 8, 2017
Latest reply on Dec 9, 2017 by Jack Peacock

Hello,

I got connected measuring device to my STM32F4 - Discovery board (with Open407V-D board). They are communication via RS 485 bus. Measuring device should provide result of measurement after request., but after some time UART remain in BUSY state. I get valid results for cca 4 cycles and then UART freeze. Could you help me to find problem?

 

Here is my main() code:

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART3_UART_Init();
    
    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET);

 

  while (1)
    {
        while(huart3.gState != HAL_UART_STATE_READY);
        HAL_UART_Transmit_IT(&huart3, (uint8_t*)aTxBuffer, 2);
        while(huart3.RxState != HAL_UART_STATE_READY);
        HAL_UART_Receive_IT(&huart3, (uint8_t*)aRxBuffer, 4);

 

        while(DataRecieved == 0);
        GetMeasurementValue();
        MeasuredDistance = MeasurementValue * 10.0 / 16384.0;
  }
}

 

After IRQ I am managing RS 485 input/output pin and variable:

 

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
{
  /* Set transmission flag: transfer complete */
    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET);
    DataRecieved = 0;
}

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
  /* Set transmission flag: transfer complete */
    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET);
    DataRecieved = 1;
}

 

And my UART settings:

static void MX_USART3_UART_Init(void)
{

  huart3.Instance = USART3;
  huart3.Init.BaudRate = 38400;
  huart3.Init.WordLength = UART_WORDLENGTH_9B;
  huart3.Init.StopBits = UART_STOPBITS_1;
  huart3.Init.Parity = UART_PARITY_EVEN;
  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(__FILE__, __LINE__);
  }

 

}

 

Any suggestions where is problem? Thank you very much.

Outcomes