Getting consistent garbage on serialport terminal using 8051 UART Announcing the arrival of...

Identify plant with long narrow paired leaves and reddish stems

How come Sam didn't become Lord of Horn Hill?

Why do people hide their license plates in the EU?

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

Error "illegal generic type for instanceof" when using local classes

What does the "x" in "x86" represent?

Why was the term "discrete" used in discrete logarithm?

What's the meaning of 間時肆拾貳 at a car parking sign

Naming the result of a source block

Why is my conclusion inconsistent with the van't Hoff equation?

What is Wonderstone and are there any references to it pre-1982?

Using audio cues to encourage good posture

What exactly is a "Meth" in Altered Carbon?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

Should I use a zero-interest credit card for a large one-time purchase?

ListPlot join points by nearest neighbor rather than order

How do I keep my slimes from escaping their pens?

How widely used is the term Treppenwitz? Is it something that most Germans know?

Should I discuss the type of campaign with my players?

Bete Noir -- no dairy

Is it fair for a professor to grade us on the possession of past papers?

Can I cast Passwall to drop an enemy into a 20-foot pit?

Apollo command module space walk?

How does debian/ubuntu knows a package has a updated version



Getting consistent garbage on serialport terminal using 8051 UART



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Valid 16550 UART settingsUsing an Ettus USRP on an embedded systemGetting garbage input and output over serial connection with microcontrollerserial port over tcp without terminal serverSerial console login on OSXMy UART receive a null character sometimesWhat is the type of the UART chip used by Virtual Box?Clear command for serial terminal over UARTTrying to get UART to work on a dsPIC33EV256GM102Reading L&T ER300P based on DLMS Protocol





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















This is my first time dealing with micro controllers and I was assigned to assemble a board with a 8051 micro controller and I was given a code to program it with.



The code should print out "Testing Serial UART" at the beginning but instead it prints out garbage every time I press the reset button to make the code run from the
beginning again I get the same consistent garbage.



I have triple checked the baud rate which is set to 9600 and yet with no luck in running it.



Here is my code:



#include <reg51.h>

#define Input P0

#define Output P2

void SetupSerial()
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */

/* TH1 = ( 256 - ((22.1184MHZ / 12 ) / 32) / BaudRate ) = 256 - 6 = 250 */
TH1 = 250; /* TH1: reload value for 9600 baud @ 22.1184MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1;
RI = 1;
}

void __putchar(unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0;
}

unsigned char __getchar()
{
unsigned char ch;

while(RI == 0);
ch = SBUF;
RI = 0;
return ch;
}

void printString(const char *s)
{
while(*s)
__putchar(*(s++));
}

unsigned char ToASCII(unsigned char val)
{
if( val >= 0 && val <=9 )
return val + '0';
else if ( val >= 0x0A && val <= 0x0F)
return val + 'A' - 10;
else
return ' ';
}

void main()
{
unsigned char key = ' ';
unsigned char half_port;

SetupSerial();

printString("rnTesting Serial UARTrn");

P1 = 0x0F;
while(1)
{
key = __getchar();

switch(key)
{
case 'R':
case 'r':
half_port = Input & 0x0F;
__putchar( ToASCII(half_port));
Output = ~half_port;
break;
}

}

}


and this is the diagram I am working on:



diagram



This is the garbage i get and every time i press reset on the micro controller the same chars keeps printing from what i understood from this assignment each time we reset it should print "Testing Serial UART" until i send an "R" then it goes on to do something else



And this is my board:



board



this is the string that appears in text it was only repeated because i pressed reset a few times so the baud rate isn't the problem










share|improve this question









New contributor




Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • (1) A bit of general advice: you should use defined constants whenever possible.  Your 0x50 should be replaced with SM1|REN or SCON_MODE1|REN, and your 0x20 should be replaced with M1 or TMOD_MODE2, or whatever they’re called in your environment.  (2) What are Input and Output?  (3) What debugging have you done?  (3a) You say that you “get the same consistent garbage”; have you actually taken screenshots and verified that the results are always the same nonsense characters?  (3b) Have you tried sending other strings?  … (Cont’d)

    – G-Man
    15 hours ago











  • (Cont’d) …  Strings of many spaces, @ signs or question marks (?) might yield interesting results.  (3c) I’m sorry; I see that you say that you’ve checked the baud rate three times — but a ratio of 23 characters sent to 150 characters received is a big red flag of a baud rate discrepancy.  Have you tried changing the settings on your SerialPort Terminal?  (3d) Have you tried using the “Hex” Data Mode in your SerialPort Terminal? … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – G-Man
    15 hours ago




















0















This is my first time dealing with micro controllers and I was assigned to assemble a board with a 8051 micro controller and I was given a code to program it with.



The code should print out "Testing Serial UART" at the beginning but instead it prints out garbage every time I press the reset button to make the code run from the
beginning again I get the same consistent garbage.



I have triple checked the baud rate which is set to 9600 and yet with no luck in running it.



Here is my code:



#include <reg51.h>

#define Input P0

#define Output P2

void SetupSerial()
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */

/* TH1 = ( 256 - ((22.1184MHZ / 12 ) / 32) / BaudRate ) = 256 - 6 = 250 */
TH1 = 250; /* TH1: reload value for 9600 baud @ 22.1184MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1;
RI = 1;
}

void __putchar(unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0;
}

unsigned char __getchar()
{
unsigned char ch;

while(RI == 0);
ch = SBUF;
RI = 0;
return ch;
}

void printString(const char *s)
{
while(*s)
__putchar(*(s++));
}

unsigned char ToASCII(unsigned char val)
{
if( val >= 0 && val <=9 )
return val + '0';
else if ( val >= 0x0A && val <= 0x0F)
return val + 'A' - 10;
else
return ' ';
}

void main()
{
unsigned char key = ' ';
unsigned char half_port;

SetupSerial();

printString("rnTesting Serial UARTrn");

P1 = 0x0F;
while(1)
{
key = __getchar();

switch(key)
{
case 'R':
case 'r':
half_port = Input & 0x0F;
__putchar( ToASCII(half_port));
Output = ~half_port;
break;
}

}

}


and this is the diagram I am working on:



diagram



This is the garbage i get and every time i press reset on the micro controller the same chars keeps printing from what i understood from this assignment each time we reset it should print "Testing Serial UART" until i send an "R" then it goes on to do something else



And this is my board:



board



this is the string that appears in text it was only repeated because i pressed reset a few times so the baud rate isn't the problem










share|improve this question









New contributor




Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • (1) A bit of general advice: you should use defined constants whenever possible.  Your 0x50 should be replaced with SM1|REN or SCON_MODE1|REN, and your 0x20 should be replaced with M1 or TMOD_MODE2, or whatever they’re called in your environment.  (2) What are Input and Output?  (3) What debugging have you done?  (3a) You say that you “get the same consistent garbage”; have you actually taken screenshots and verified that the results are always the same nonsense characters?  (3b) Have you tried sending other strings?  … (Cont’d)

    – G-Man
    15 hours ago











  • (Cont’d) …  Strings of many spaces, @ signs or question marks (?) might yield interesting results.  (3c) I’m sorry; I see that you say that you’ve checked the baud rate three times — but a ratio of 23 characters sent to 150 characters received is a big red flag of a baud rate discrepancy.  Have you tried changing the settings on your SerialPort Terminal?  (3d) Have you tried using the “Hex” Data Mode in your SerialPort Terminal? … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – G-Man
    15 hours ago
















0












0








0








This is my first time dealing with micro controllers and I was assigned to assemble a board with a 8051 micro controller and I was given a code to program it with.



The code should print out "Testing Serial UART" at the beginning but instead it prints out garbage every time I press the reset button to make the code run from the
beginning again I get the same consistent garbage.



I have triple checked the baud rate which is set to 9600 and yet with no luck in running it.



Here is my code:



#include <reg51.h>

#define Input P0

#define Output P2

void SetupSerial()
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */

/* TH1 = ( 256 - ((22.1184MHZ / 12 ) / 32) / BaudRate ) = 256 - 6 = 250 */
TH1 = 250; /* TH1: reload value for 9600 baud @ 22.1184MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1;
RI = 1;
}

void __putchar(unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0;
}

unsigned char __getchar()
{
unsigned char ch;

while(RI == 0);
ch = SBUF;
RI = 0;
return ch;
}

void printString(const char *s)
{
while(*s)
__putchar(*(s++));
}

unsigned char ToASCII(unsigned char val)
{
if( val >= 0 && val <=9 )
return val + '0';
else if ( val >= 0x0A && val <= 0x0F)
return val + 'A' - 10;
else
return ' ';
}

void main()
{
unsigned char key = ' ';
unsigned char half_port;

SetupSerial();

printString("rnTesting Serial UARTrn");

P1 = 0x0F;
while(1)
{
key = __getchar();

switch(key)
{
case 'R':
case 'r':
half_port = Input & 0x0F;
__putchar( ToASCII(half_port));
Output = ~half_port;
break;
}

}

}


and this is the diagram I am working on:



diagram



This is the garbage i get and every time i press reset on the micro controller the same chars keeps printing from what i understood from this assignment each time we reset it should print "Testing Serial UART" until i send an "R" then it goes on to do something else



And this is my board:



board



this is the string that appears in text it was only repeated because i pressed reset a few times so the baud rate isn't the problem










share|improve this question









New contributor




Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












This is my first time dealing with micro controllers and I was assigned to assemble a board with a 8051 micro controller and I was given a code to program it with.



The code should print out "Testing Serial UART" at the beginning but instead it prints out garbage every time I press the reset button to make the code run from the
beginning again I get the same consistent garbage.



I have triple checked the baud rate which is set to 9600 and yet with no luck in running it.



Here is my code:



#include <reg51.h>

#define Input P0

#define Output P2

void SetupSerial()
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */

/* TH1 = ( 256 - ((22.1184MHZ / 12 ) / 32) / BaudRate ) = 256 - 6 = 250 */
TH1 = 250; /* TH1: reload value for 9600 baud @ 22.1184MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1;
RI = 1;
}

void __putchar(unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0;
}

unsigned char __getchar()
{
unsigned char ch;

while(RI == 0);
ch = SBUF;
RI = 0;
return ch;
}

void printString(const char *s)
{
while(*s)
__putchar(*(s++));
}

unsigned char ToASCII(unsigned char val)
{
if( val >= 0 && val <=9 )
return val + '0';
else if ( val >= 0x0A && val <= 0x0F)
return val + 'A' - 10;
else
return ' ';
}

void main()
{
unsigned char key = ' ';
unsigned char half_port;

SetupSerial();

printString("rnTesting Serial UARTrn");

P1 = 0x0F;
while(1)
{
key = __getchar();

switch(key)
{
case 'R':
case 'r':
half_port = Input & 0x0F;
__putchar( ToASCII(half_port));
Output = ~half_port;
break;
}

}

}


and this is the diagram I am working on:



diagram



This is the garbage i get and every time i press reset on the micro controller the same chars keeps printing from what i understood from this assignment each time we reset it should print "Testing Serial UART" until i send an "R" then it goes on to do something else



And this is my board:



board



this is the string that appears in text it was only repeated because i pressed reset a few times so the baud rate isn't the problem







serial-port embedded microcontroller






share|improve this question









New contributor




Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 11 hours ago







Ali Osman













New contributor




Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 18 hours ago









Ali OsmanAli Osman

11




11




New contributor




Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Ali Osman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • (1) A bit of general advice: you should use defined constants whenever possible.  Your 0x50 should be replaced with SM1|REN or SCON_MODE1|REN, and your 0x20 should be replaced with M1 or TMOD_MODE2, or whatever they’re called in your environment.  (2) What are Input and Output?  (3) What debugging have you done?  (3a) You say that you “get the same consistent garbage”; have you actually taken screenshots and verified that the results are always the same nonsense characters?  (3b) Have you tried sending other strings?  … (Cont’d)

    – G-Man
    15 hours ago











  • (Cont’d) …  Strings of many spaces, @ signs or question marks (?) might yield interesting results.  (3c) I’m sorry; I see that you say that you’ve checked the baud rate three times — but a ratio of 23 characters sent to 150 characters received is a big red flag of a baud rate discrepancy.  Have you tried changing the settings on your SerialPort Terminal?  (3d) Have you tried using the “Hex” Data Mode in your SerialPort Terminal? … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – G-Man
    15 hours ago





















  • (1) A bit of general advice: you should use defined constants whenever possible.  Your 0x50 should be replaced with SM1|REN or SCON_MODE1|REN, and your 0x20 should be replaced with M1 or TMOD_MODE2, or whatever they’re called in your environment.  (2) What are Input and Output?  (3) What debugging have you done?  (3a) You say that you “get the same consistent garbage”; have you actually taken screenshots and verified that the results are always the same nonsense characters?  (3b) Have you tried sending other strings?  … (Cont’d)

    – G-Man
    15 hours ago











  • (Cont’d) …  Strings of many spaces, @ signs or question marks (?) might yield interesting results.  (3c) I’m sorry; I see that you say that you’ve checked the baud rate three times — but a ratio of 23 characters sent to 150 characters received is a big red flag of a baud rate discrepancy.  Have you tried changing the settings on your SerialPort Terminal?  (3d) Have you tried using the “Hex” Data Mode in your SerialPort Terminal? … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – G-Man
    15 hours ago



















(1) A bit of general advice: you should use defined constants whenever possible.  Your 0x50 should be replaced with SM1|REN or SCON_MODE1|REN, and your 0x20 should be replaced with M1 or TMOD_MODE2, or whatever they’re called in your environment.  (2) What are Input and Output?  (3) What debugging have you done?  (3a) You say that you “get the same consistent garbage”; have you actually taken screenshots and verified that the results are always the same nonsense characters?  (3b) Have you tried sending other strings?  … (Cont’d)

– G-Man
15 hours ago





(1) A bit of general advice: you should use defined constants whenever possible.  Your 0x50 should be replaced with SM1|REN or SCON_MODE1|REN, and your 0x20 should be replaced with M1 or TMOD_MODE2, or whatever they’re called in your environment.  (2) What are Input and Output?  (3) What debugging have you done?  (3a) You say that you “get the same consistent garbage”; have you actually taken screenshots and verified that the results are always the same nonsense characters?  (3b) Have you tried sending other strings?  … (Cont’d)

– G-Man
15 hours ago













(Cont’d) …  Strings of many spaces, @ signs or question marks (?) might yield interesting results.  (3c) I’m sorry; I see that you say that you’ve checked the baud rate three times — but a ratio of 23 characters sent to 150 characters received is a big red flag of a baud rate discrepancy.  Have you tried changing the settings on your SerialPort Terminal?  (3d) Have you tried using the “Hex” Data Mode in your SerialPort Terminal? … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

– G-Man
15 hours ago







(Cont’d) …  Strings of many spaces, @ signs or question marks (?) might yield interesting results.  (3c) I’m sorry; I see that you say that you’ve checked the baud rate three times — but a ratio of 23 characters sent to 150 characters received is a big red flag of a baud rate discrepancy.  Have you tried changing the settings on your SerialPort Terminal?  (3d) Have you tried using the “Hex” Data Mode in your SerialPort Terminal? … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

– G-Man
15 hours ago












0






active

oldest

votes












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Ali Osman is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1426031%2fgetting-consistent-garbage-on-serialport-terminal-using-8051-uart%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Ali Osman is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Ali Osman is a new contributor. Be nice, and check out our Code of Conduct.













Ali Osman is a new contributor. Be nice, and check out our Code of Conduct.












Ali Osman is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1426031%2fgetting-consistent-garbage-on-serialport-terminal-using-8051-uart%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...