STM32F407 USART failed to receive when using DMA to transmit
I have two custom boards, one with a STM32F407 MCU that I use as a USART RS485 master, the other configured as a USART RS485 slave that echoes back everything I send from the master.
I'm using the HAL libaray, and have successfully tested some simple communication between the two devices, i.e., master send a byte to slave, slave echo back, then master will print out the receivd byte.
But when I tried to include DMA in the trasmitting process, the master can send messages as usual, but failed to receive anything even though I have used an oscillascope the check that the slave is still working properly.
This is the code snippet that works:
void rs485_send(uint8_t * buf, uint8_t len)
{
/* Enable output by driving EN pin high */
HAL_GPIO_WritePin(RS485_TX_GPIO_PORT, RS485_EN_PIN, GPIO_PIN_SET);
HAL_UART_Transmit(&UartHandle, buf, len, 0xFF);
/* Enable input by driving EN pin low */
HAL_GPIO_WritePin(RS485_TX_GPIO_PORT, RS485_EN_PIN, GPIO_PIN_RESET);
}
This is the code snippet that does not work:
void rs485_send(uint8_t * buf, uint8_t len)
{
/* Enable output by driving EN pin high */
HAL_GPIO_WritePin(RS485_TX_GPIO_PORT, RS485_EN_PIN, GPIO_PIN_SET);
HAL_UART_Transmit_DMA(&UartHandle, buf, len);
}
void DMA1_Stream4_IRQHandler()
{
HAL_DMA_IRQHandler(&DMAHandle_Tx);
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == RS485_UARTx)
{
/* Enable input by driving EN pin low */
HAL_GPIO_WritePin(RS485_TX_GPIO_PORT, RS485_EN_PIN, GPIO_PIN_RESET);
}
}
My only guess is that the slave echoed back before the Enable Pin is driven low to allow master to start receiving, but have no idea how to properly solve this issue, can anyone help me with this? Much appreicated!
