Skip to main content
LimoGr
Associate II
March 29, 2023
Question

UART LOOP using registers

  • March 29, 2023
  • 5 replies
  • 2649 views

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!

This topic has been closed for replies.

5 replies

Tesla DeLorean
Guru
March 29, 2023

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Pavel A.
March 29, 2023
#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 II
March 30, 2023

> 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
LimoGrAuthor
Associate II
March 30, 2023

Post deleted to adhere community guidelines.

LCE
Principal II
March 30, 2023

 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
LimoGrAuthor
Associate II
March 30, 2023

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

Karl Yamashita
Principal
March 31, 2023

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

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source