0
votes

I am struggling to get UART sending data after receiving using circular DMA for RX and normal mode for TX.

in main(void)

HAL_UART_Receive_DMA(&huart2,rx_buff,INCOMING_SETTING_STRING_SIZE);
HAL_UART_Transmit_DMA(&huart2, tx_buff, OUTGOING_SETTING_SIZE);

UART Settings

static void MX_USART2_UART_Init(void)
{

  huart2.Instance = USART2;
  huart2.Init.BaudRate = 9600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
}

RX Callback

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    ProcessSerialSettings();

    HAL_UART_Transmit_DMA(&huart2,(uint8_t *)'ACK\n',5);

    memset(rx_buff,0,sizeof(rx_buff));
}

I'm sure I must be missing something as it almost seems too simple. The data continues to come into the device as the "processSerialSettings" function updates some a couple of variables, without doubt, every time. I want to receive a settings string, update a couple of variables and return an acknowledgement.

After further debugging I now know that the state of the port is busy, however how can this be the case when I haven't sent anything over the TX line? If I change the TX DMA mode to circular it spams the serial port basically until my terminal window crashes.

Thanks!

1

1 Answers

-1
votes

Solved this by removing the transmit DMA all together and transmitting using:

HAL_UART_Transmit(&huart2,(uint8_t *)'ACK\n',5);