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, need help on UART receiving

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,
I need help for 8051 serial communication with computer.
While sending strings to computer goes OK I have serious problem with receiving.
Mostly because I don't understand this part well.

This is critical part of my 8051 C code:

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 to see what happens
        		RI = 0;
                      // here is key check for terminate receiving...
                      goto again;

I send from computer numbers from 0 to 15 as strings.
This is VB.NET code:

Code:
        For t As Integer = 0 To 15
            Application.DoEvents()
            Form1.sPort.Write(CStr(t)) 'it have to be a string?
            Sleep(3000)
        Next

What happens?
Bytes arrived to SBUF with values 0-7 and beeing showed on first 4 leds of port P1.
When commes a number greater than 9 (say "10") then two bytes arrives.
But I need to send from computer numbers from 0 to 255 to be visible on all bytes of P1.

What should I do to achieve this?
 

sent asccii via the port.
Code:
        For t As char = 0 To 15
            Application.DoEvents()
            Form1.sPort.Write(t) 'it have to be a string?
            Sleep(3000)
        Next
 

That gives a same result. VB.NET convert number to char anyway by himself.
Why I get showed on P1 only 4 bit numbers?
 

I do sent "a".
And get 10000110 on P1.
For "A" I get 10000010.
 

This is problem.
If I send 255 then port goes to 10101100!
First four bits is 5, and I think that UART receives more than one byte but passes too fast to see.
 

dim b as string
For t As char = 0 To 255
b = chr (t)
Application.DoEvents()
Form1.sPort.Write(b) 'it have to be a string?
Sleep(3000)
Next t
 
Last edited:
I tried.
Please note that "data" is reserved word in keil C so I have to change that in order to compile, right?
After all result is a same.
I finishes with 10101100 on P1.

But led's shortly flashes what says that more than one byte arrives.
 

Hm, Magvitron,
The best what I can get from your suggestions is this:

Code:
        Dim b As String
        For t As Byte = 0 To 255
            b = Chr(t)
            Application.DoEvents()
            Form1.sPort.Write(b)
            Sleep(100)
        Next t

This counts to 127 (7bits) and for other 127 (to 255) nothing happens on P1.

EDIT:
A bit shorter, also work's up to 127.
Code:
        For t As Integer = 0 To 255
            Form1.sPort.Write(Chr(t))
        Next t

I would like to know why P1 dont show values from 128-255...
 
Last edited:

Well, solution is really ODD, but I find it on the net now...

If someone ever will need to send integers 0 to 255 to UART through VB.NET:
Code:
Dim r As Integer = 255  'your integer

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

Magvitron, thanks for helping...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top