My program is writing garbage to the serial port. Why?
Submitted By: Craig Steiner FAQ Last Modified: 07/10/06
- It is not uncommon, especially for beginners, to write a program that is supposed to send data out the serial port only to receive garbage or garbled data instead of the expect information. Common causes for this are:
- Are you sure you configured the serial port and timer correctly to achieve the desired baud rate? Do the calculations again and make sure you got it right.
- Does your calculated baud rate error (see #2 above) exceed 3%? You might need to use another oscillator with a baud rate-friendly speed. 11.0592MHZ is one of the most popular.
- Is the receiving program (i.e., your PC or other device) set to the same baud rate? Double check. You might also want to try setting your PC to other common baud rates (300, 1200, 2400, etc.) just to see if, by chance, you accidentally configured the 8052 to another baud rate. If you find that you find everything working when you set your PC to 2400 baud, you *know* that you messed up the baud rate calculation. See question #1 to correct your baud rate.
- Is your program waiting until the TI bit (SCON.1) is set before sending the next character? If your program sends a character before the serial port has had sufficient time to send out the previous character, you are inevitably going to garble your transmission. Try sending only one character and then looping infinitely. If that one character is received without problem, try sending two characters and then looping infinitely. If that fails, you probably have a problem related to waiting for the TI bit. Check question #3 above.
Add Information to this FAQ: If you have additional information or alternative solutions to this question, you may add to this FAQ by clicking here.