cancel
Showing results for 
Search instead for 
Did you mean: 

UART LOOP using registers

LimoGr
Associate II

Hi ! This is me again !

I am able to send and receive separately but when try to do the loop, it doesnt work.

What I am basically doing is when the full reception interrupt is set, I enable the transmission and as soon as the transmission is done, I disable it.

It works if I write any data but when I try to send back the received data, it doesn't. Can someone point to some errors or give me some tips/remarks?

Thank you!

8 REPLIES 8

How does it synchronize or move data between the buffers?

The TX is just going to saturate in a continuous loop, sending as fast as possible.

The RX is going to pace at the rate data comes it. He it will stall until it hits TC

Not sure I'm at all interested in decoding register bits on uncommented code, hard to determine intent.

Shouldn't have massive delays in IRQ handlers.

You need to think harder about managing, buffering and sequencing. Best to understand the mechanics rather than stab at the problem and hope.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III
#include <stm32f7xx_ll_usart.h>
 
void uart_loop(USART_TypeDef *UW, USART_TypeDef *UT)
{
  for(;;)
  {
     if (LL_USART_IsActiveFlag_RXNE(UW)) {
	 if (LL_USART_IsActiveFlag_TXE(UT)) {
	     LL_USART_TransmitData8(UT, LL_USART_ReceiveData8(UW));
	 }
     }
 
     if (LL_USART_IsActiveFlag_RXNE(UT)) {
	 if (LL_USART_IsActiveFlag_TXE(UW)) {
	     // Stop on ^C
	     uint8_t ch = LL_USART_ReceiveData8(UT);
	     if (ch == 3) {
		 break;
	     }
	     LL_USART_TransmitData8(UW, ch);
	 }
     }
  }
}

LCE
Principal

> USART2->CR1 |= (1<<3);

As Tesla said, this is not very readable. Better use the pre-defined register bit definitions from the specific STM's header file.

Post edited to adhere community guidelines.

LimoGr
Associate II

Post deleted to adhere community guidelines.

 Will you still know in a year what bit 3 of register USART2->CR1 means?

Amazing if yes, I would not.

So using these defines do not only help "readability", but also remembering what's it about.

So, my comment was supposed to be helpful.

Do you expect the other users to check every register's bit? Download and check RM...

I'm using the UART a lot, but I don't know every bit of every register of every STM32 by heart.

Post edited to adhere community guidelines.

LimoGr
Associate II

I am sorry I did not mean you. You are right and that's what I did the second I read the answers, I added comments to each line of the code but there are different ways of pointing to someone's mistakes

So, to whom was it meant then? Tesla?

Karl Yamashita
Lead II

@LimoGr​ post your code so we can dissect the issue.

I Can't Believe It's Not Butter. If you find my answers useful, click the accept button so that way others can see the solution.