building a software UART

Posted on 2004-11-12
Last Modified: 2013-12-09
ok brainy low level c guys.
     how difficult is it to write a software uart, as opposed to adding an actual Hardware UART to my board? and what are the typical first timer mistakes i need to look out for?
Question by:bythefsh
    LVL 12

    Accepted Solution

    Hi bythefsh,

    A UART is the chip that actually converts a serial bit stream into a byte values. It will scan input ports according to a defined baud rate, check for framing information and may have to deal with handshake lines. This is done for incoming and outgoing information.

    Now I am not sure what hardware you are on, but dealing with serial I/O on that level might take up quite some resources fro your CPU.

    LVL 22

    Assisted Solution

    I wouldnt recommend a software UART, especially if the CPU has any other real-time things to respond to.

    If you must, the most efficient way is to set up a timer interrupt at 16x the baud rate, then on each interrupt you can check to see if the start bit has begun.  Then skip 8 counts and sample again, you shoul dnow be in the middle of the start bit.  Then skip 16 counts and sample the 8 bits every 16 counts.  then check for the stop bit.  Not too hard if you're used to interrupt routines.

    That's for receiving, for sending you just do the opposite, send one bit at each timer interrupt.
    LVL 55

    Expert Comment

    by:Jaime Olivares
    Feasibility will depend on Platform & Operating System.
    If you are working with a Windows/Intel OS/Platform, then will be a little hard to ensure proper timing because windows does some task simultaneously that can consume system resources avoiding you to transmit in proper time.
    If you are working with a non-multitasking operating system like DOS, this could be done succefully using many techniques, polled or interrupted, as proposed by grg99.
    If you are working with a microcontroller, it could be done also without problems, there are many ways to do it and is very popular in PicMicro microcontrollers, because most of them didn't use to have a real UART.
    But notice that, depending on technique choosen you will be able or not to do full-duplex communication.

    Please specify Platform and OS.

    Good luck,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    More and more people are using the enhanced small form-factor pluggable (SFP+) tranceivers, and speed is of utmost importance. Testing of speeds are critical to ensure that the devices will meet the speed requirements. There are some testing challen…
    Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
    This video discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now