UART programming
Results 1 to 4 of 4

Thread: UART programming

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    161

    UART programming

    Hi, i haven't posted in a while. I need to know if any of you has ever done any programs for an UART? I need to finish a program (in C) for school in which I need to transfer files through a null modem, any help or tips will be appreciated. I am pretty sure my program sends data (i have debugged extensively), my problem right now is in the receiving part.

    thanx

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    Yep, I have

    Sounds pretty low-level. I take it you're using rs232 or something compatible. Can't you just hook your apparatus up to a PC and write some software which emulates the device you want to talk to?

    I cannot advise you unless you state

    - What your platform is (microcontroller, microprocessor, 8 bit, 16 bit?)
    - What your application is (i.e. what device you're trying to talk to, what protocol you intend to use)
    - What electrical standard you're using (I assume seeing as you mention "null modem", it's rs232)

    Oh yes, and stating what UART it is might help too!

  3. #3
    Senior Member
    Join Date
    Apr 2002
    Posts
    161
    UART- universal asynchronous reciever transmitter, it is the piece of hardware used to control serial communications, on serial ports. The address of an uart is your com port address ie: 0x3f8, to access different registers on the uart you add an offset to your address to reach the desired regs to do different functions: choose speed, parity, data field size etc. I have already defined that.
    I don't need to emualte the rs 232 protocol. I just need to write some code to trasnmit any file byte by byte from one pc to another using a null modem cable, its like creating my own protocol, much simpler than rs 232. I am using Turbo C compiler, I am sure it could be done using assembly but now I am sticking to C which lets you go pretty low level.

  4. #4
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    Right. I know what UART stands for but I didn't realise you were using PC hardware, I assumed it was some sort of embedded system using an 8 or 16bit CPU in C or assembly.

    There are many different UARTS, but the ones PCs have in (or modern hardware emulates anyway) are fairly well documented.

    RS232 is an electrical standard, you will definitely be using it. Creating your own protocol at this level involves soldering.

    There are usually two ways to go to receive bytes with a UART

    - Polling
    Pros: Easy
    Cons: if you stop polling for too long (i.e. more than the hardware buffer), you miss stuff.

    - Interrupts
    Pros: Reliable
    Cons: Requires some assembly and knowedge of the platform, i.e. how to catch interrupts. Programming interrupts requires synchronisation to ensure that you don't try and access the same area at the same time between an interrupt and foreground task.

    I have programmed UARTs on 8-bit platforms before, they (6850) only had a 1 byte buffer, so you had to respond quickly otherwise data would get lost.

    You typically had to implement your own software buffer, because processing a message usually takes longer than the time before the second byte of the next message arrives.

    If you're using a fast machine and short, easy messages, you may not need interrupts (polling might be fast enough).

    On the other hand, if you're doing IO in DOS, that is incredibly slow, so you will definitely need interrupts (unless you plan on reading the file into memory entirely before saving it out)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •