Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Only a small 89s52 uart problem

Status
Not open for further replies.

garg29

Advanced Member level 1
Advanced Member level 1
Joined
Nov 17, 2004
Messages
443
Helped
25
Reputation
50
Reaction score
10
Trophy points
1,298
Activity points
3,593
uart_gets

Hi friends, i'm just trying to do communication between 2-89S52 microcontrollers.

One is transmitting "HELLO" & other is receiving the same & displaying it on LCD(16x2). The transmitting point is OK as I have checked the result on Hyperterminal. Receiving end is also displaying "HELLO" but with a small problem, at the First instance the word "HELLO" is displayed properly but after that it's displayed as "HHELLO" i.e. character 'H' is displayed twice. In function "void uart_gets(char *s)" I tried putting a line "s--;" this displayed "ELLO" ('H' vanished) first time but "HELLO" (proper) continoulsy after that. below is the code.
Thanks everyone for giving time to read my problem.


Regards.
 

small application using 89s52

Code:
char uart_getc(void)   // Get Character from UART
   {
      //SBUF=0; // why?????
      while(RI==0);RI=0;
      return SBUF;
   }
well I don't know why you send a character 0...

mmm could you post the "Lcd_74595.h" file? maybe it changes the pointer (*s)... also, could you change the global string "char s[7]" to another name.. maybe
Code:
char str[7],i;

// and further...

       
      uart_gets(str);
      lcd_puts(str);

I think the lcd_puts changes the pointer... well that's just an idea...
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
89c52 uart

Thanks for replying Kurenai_ryu. I just tried putting SBUF=0; but that did'nt made any change. I also tried str[7] but that also didn't helped.

Here's my code for LCD
Code:
void
lcd_puts(const char * s)
{
	LCD_RS = 1;	// write characters
	while(*s)
		lcd_write(*s++);
}

Thanks once again.
 

uart giving only null

The problem is not the ”extra” ’H’ you see, but what you don’t see!
I’m guessing your transmitter side send a “HELLO\r\n” (that’s a regular “Enter”, or a CR=0x0D (13) followed by a LF=0x0A (10)).
Your ‘uart_gets()’ waits until it sees a CR (13), it replaces it with NULL and returns, but in UART’s receive buffer there will be a LF (10) char left for the next time you call ‘uart_gets()’, and that char will be retrieved as the first element in your string, before the H.
You’ll have to deal with all the received characters, and flush them (and no, SBUF=0 won’t do, you’ll have to do a dummy read instead).

Please don’t mind me saying that your coding style just begs for errors. Although correct, your choice to name formal parameters with the same name as global ones is very confusing, to not mention the obfuscation of the rest of the code.
I hope you realize that this will only work in this particular case and in no way should you use this code as a template for general purpose.

Arthur
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top