Question
Tx to Rx UART DMA loopback
Hello,
The Tx and Rx pins of UART 4 in my code are shorted.
I want to send an incrementing array from the Tx pin and receive it back from the Rx pin.
For this I wrote a for loop that increments every element of the array. The for loop is run from the callback function of HAL_UART_Receive_DMA.
But I receive "uart4_rx_buffer" only once.
What's wrong with my code ?
uint8_t uart4_tx_buffer [ 8 ] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 } ;
uint8_t uart4_rx_buffer [ 8 ] = { 0 } ;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_DMA_Init();
MX_UART4_Init();
HAL_UART_Receive_DMA ( & huart4 , uart4_rx_buffer , 8 ) ;
HAL_UART_Transmit_DMA ( & huart4 , uart4_tx_buffer , 8 ) ;
while ( 1 ) ;
}
void HAL_UART_RxCpltCallback ( UART_HandleTypeDef * huart )
{
for ( int index = 0 ; uart4_tx_buffer < 8 ; index ++ )
{
uart4_tx_buffer [ index ] = uart4_tx_buffer [ index ] + 8 ;
HAL_UART_Transmit_DMA ( & huart4 , uart4_tx_buffer , 8 ) ;
}
} 