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.

[SOLVED] 8051, receiving data to UART

Status
Not open for further replies.

bitsurfer

Member level 3
Joined
Jul 19, 2012
Messages
56
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Croatia
Activity points
1,734
Hello,
While I can send data to computer well, and from computer too I have problems with accurately receiving data to 8051 mC.
Here is my VB.NET code for sending bytes:

Code:
        For a As Integer = 1 To 10
            For t As Integer = 0 To 255
                Form1.sPort.Write(Chr(t))
            Next
        Next

For sure, this code sends 2550 bytes.

And here is C code for receiving bytes:

Code:
again:
            while(RI!=0)
            {
                P1=SBUF;
                RI=0;
                receivedBytes++;
            }
            show_lcd_received_bytes(receivedBytes);
            goto again;

By watching variable receivedBytes it take only 190-210 bytes (every time different) because computer dumps data to port without any synchronisation.
Is here any technique or method to receive full data fast and proper?

I also try receiving data with serial interrupt with same results.

This is, of course, not usable in any practical application.
What to do here?
 

maybe continuing receive 2550bytes need a long time,why you not try send more times.every times send/receive 200bytes
 

Hello,
While I can send data to computer well, and from computer too I have problems with accurately receiving data to 8051 mC.
Here is my VB.NET code for sending bytes:

Code:
        For a As Integer = 1 To 10
            For t As Integer = 0 To 255
                Form1.sPort.Write(Chr(t))
            Next
        Next

For sure, this code sends 2550 bytes.

And here is C code for receiving bytes:

Code:
again:
            while(RI!=0)
            {
                P1=SBUF;
                RI=0;
                receivedBytes++;
            }
            show_lcd_received_bytes(receivedBytes);
            goto again;

By watching variable receivedBytes it take only 190-210 bytes (every time different) because computer dumps data to port without any synchronisation.
Is here any technique or method to receive full data fast and proper?

I also try receiving data with serial interrupt with same results.

This is, of course, not usable in any practical application.
What to do here?


At the transmitter end (computer) try to introduce a delay (10ms or longer) between consecutive bytes (timer or dummy loop), and at the receiver end (8051) the only way of receiving all characters is to use serial port interrupt and a decent size buffer ...
:wink:
IanP
 

use something like this
Vb code
Code:
Dim r As Integer = 255  'your integer

        Form1.sPort.Encoding = System.Text.Encoding.GetEncoding(1250)
        Form1.sPort.Write(Chr(r))
for the 8051

Code:
SCON = 0x50;
         TMOD = 0x20; //timer 1, mode 2, 8-bit reload
         TH1  = 0xFD; //reload value for 9600 baud
         TR1  = 1;
         TI   = 1;

again:
		while(RI!=1) 
		{;} 
        		P1 = SBUF; //send to port with led's 
        		RI = 0;
                   show_lcd_received_bytes(receivedBytes);   // here is key check for terminate receiving...
                      goto again;
 

Magvitron, sending one byte goes well, we already fixed that :)
Problem is in sending more data in loop, like sending file byte by byte and similar.

wavelet1208 & IanP, on all sides I have set 9600bps as speed, I can slow down and I can make dummy loops but this is not seem's like solution I searched for.
Will became too slow and stay still inaccurate.

Actually, I will need some way of flow control or something like this. That computer stops sending until mC "consume" last byte.

Maybe here is solution in emptying/clearing receive buffer?
As a beginner I would like to hear any advice on that.
 

you might use the RTS and CTS of the serial port for that.

I would like to try.
Any code example?

Now I think about receive buffer on 8051 side.
Where is it and how long (in bytes) is it?
Maybe I get all data but read and count only first byte of buffer?
Maybe I should loop through all characters in buffer?

Sending data to computer goes fast and without any errors... Just have to finish string with chars 13+10.
 

I just try to add timeout of 20ms to computer side for every sended byte and then all bytes passes well.
But takes too long time for practical usage.

Maybe here is some way to tell a computer to stop sending and wait until mC processes last byte, set some flag or whatever similar?
 

have you considered setting up the VB.net SerialPort object to use 2 stop bits instead of one???
 

like i said, use the Clear to sent pin of the serial port. if the data is received and acknowledged by the pc, The PC asserts RTS to indicate a desire to transmit to the UC, and the UC asserts CTS in response to grant permission. refer RS 232 communication schemes .
 
like i said, use the Clear to sent pin of the serial port. if the data is received and acknowledged by the pc, The PC asserts RTS to indicate a desire to transmit to the UC, and the UC asserts CTS in response to grant permission. refer RS 232 communication schemes .

Then I think I understand now what I have to do.
Take one free port pin and name it CTS.
Then add this pin to program:

Code:
again:
                      CTS=1;
		while(RI!=1) 
		{;} 
        		P1 = SBUF; //send to port with led's 
        		RI = 0;
                      CTS=0;
                      show_lcd_received_bytes(receivedBytes);   // here is key check for terminate receiving...
                      goto again;

Then connect this pin physically with pin 8 (CTS) on my serial output (DB9) jack on board.
And this should be that?
Have I do change something in PC side/software?

I have ready maded board with MAX232 for serial communication.
Is this matter in my case now or I should ignore it?
 

Aftar a little of reading...
Yes, it seem's that I cannot use pin signals directly but have to convert it first to RS232 voltage levels.
MAX232 have 4 TTL inputs and 4 RS232 outputs for that purpose.
By analysing my board I can see that only two I/O pairs was used for TX/RX, other two are free.
Good chance to use it for add CTS/RTS functionality when I became brave enough to make solder-works on it :)

Thanks for all which tries to clearing me a bit of this interesting area.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top