Skip to main content
Abhishek Kumar
Associate III
November 4, 2017
Question

Problem bypassing data from one UART to another?

  • November 4, 2017
  • 5 replies
  • 957 views
Posted on November 04, 2017 at 20:14

MCU: STM32F777II, running at 64MHz

Source UART: UART4 (DMA Stream configured on both RX,TX), Baud Rate: 9600

Destination UART: UART8 

(DMA Stream configured only for RX), Baud Rate: 9600

I need to bypass data coming on UART4 to UART8 not using any DMA channel, so I wrote the following code:

unsigned char strbfr[4] = '';

while(1)

{

// Block read (GPS connected)

while(HAL_UART_Receive(&UART_INT, strbfr, 1, HAL_MAX_DELAY) != HAL_OK); 

// Write data on destination UART

while(HAL_UART_Transmit(&UART_BT, strbfr, 1, 100) != HAL_OK); 

while (HAL_UART_GetState(&UART_BT) != HAL_UART_STATE_READY);

}

I see that that when the application runs, only few characters from the source i.e. the GPS device (which produces data continuously at 500ms burst rate) gets printed on the destination UART and then it stops sending. Is there any issue with this code? Is it because both source and destination are running at same baud rate? I observe that if i increase the baud rate of destination

UART8 to greater than 9600, the code runs fine, however I want to run UART8 at 9600 only due to peripheral constraints.

#stm32f7
This topic has been closed for replies.

5 replies

Tesla DeLorean
Guru
November 4, 2017
Posted on November 04, 2017 at 20:29

I would do this concurrently, rather than block on receive, block on transmit, repeat as you are doing.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Abhishek Kumar
Associate III
November 4, 2017
Posted on November 04, 2017 at 20:36

Can you please explain this in detail Clive maybe via code example, how to do this 

concurrently?

Tesla DeLorean
Guru
November 4, 2017
Posted on November 04, 2017 at 20:50

I use FIFO (Ring) Buffers that I fill using the USART RXNE interrupts, the foreground loop then checks the USART TXE state and if a character is in available in the FIFO, if there is I output the character. The loop does not block as it monitors two USART.

The FIFOs don't need to be too deep, but provides some elasticity to manage the ebb-and-flow of data and slight differences in framing or inter-symbol gaps.

It can also be done without interrupts, there the loop would test of the USART RXNE, ie

while(1) // USART Forwarder USART1<->USART2

{

  if (USART1->SR & RXNE) FifoBufferStore(Fifo1, USART1->DR);

  if (USART2->SR & RXNE) FifoBufferStore(Fifo2, USART2->DR);

  if ((USART1->SR & TXE) && (!FifoBufferEmpty(Fifo2)) USART1->DR = FifoBufferLoad(Fifo2);

  if ((USART2->SR & TXE) && (!FifoBufferEmpty(Fifo1)) USART2->DR = FifoBufferLoad(Fifo1);

 // Check overrun/framing errors, etc

}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..