cancel
Showing results for 
Search instead for 
Did you mean: 

Problem bypassing data from one UART to another?

Abhishek Kumar
Associate III
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
5 REPLIES 5
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
Up vote any posts that you find helpful, it shows what's working..
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?

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
Up vote any posts that you find helpful, it shows what's working..
Posted on November 05, 2017 at 00:16

Thanks for the reply clive, is it possible if you can share some codes for

interrupt based logic for the same?

Posted on November 05, 2017 at 12:40

Hello,

If I understand you want a code example that acts as a bridge between 2 UART? Like a Serial Pass Trough.

You can take inspiration from my project below which works on a STM32F723 Discovery and which allows to transmit each character received from one UART to another bidirectionally (take a look to wiki page for more informations)

https://github.com/rreicher/32F723EDiscovery_SerialBridge

  

This should be easy to works on an STM32F777.

The repository contains the Cube configuration file.

Bets regards

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.