1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Unable to communicate through serial port

Discussion in 'Embedded' started by Dibyendu, Jul 10, 2007.

  1. Dibyendu

    Dibyendu Guest


    I am new on this field, and taking this as hobby, but the real fact
    is, I can't communicate my 8051 microcontroller board to my PC via
    serial port. can any body help me for that issue??

    Specification of my board:

    8051 microcontroller: AT89C52 24pc.
    Cristal Oscillator: 11.0592 Mhz.
    Compiler: Keil.

    The code for the board:

    org 0
    mov TMOD, #20H ;timer 1, mode 2
    mov TH1, #-3 ;9600 boud rate
    mov SCON, #50H ;8-bit, 1 stop bin, REN enabled
    setb TR1 ;start timer 1

    again: mov SBUF, #"X" ;letter "X" to be transferred

    here: jnb TI, here ;wait for the last bit
    clr TI ;clear TI for next char
    sjmp again ; keep sending "X"


    On the PC side I am using a simple "turbo C" code [Downloaded :) ]

    #include <dos.h>
    #include <stdio.h>
    #include <conio.h>

    #define PORT1 0x3F8

    void main(void)
    int c;
    int ch;
    outportb(PORT1 + 1 , 0); /* Turn off interrupts - Port1 */

    /* PORT 1 - Communication Settings */

    outportb(PORT1 + 3 , 0x80); /* SET DLAB ON
    outportb(PORT1 + 0 , 0x0C); /* Set Baud
    rate - Divisor Latch Low Byte */

    /* 0x0C = 9,600 BPS */

    outportb(PORT1 + 1 , 0x00); /* Set Baud
    rate - Divisor Latch High Byte */
    outportb(PORT1 + 3 , 0x03); /* 8 Bits, No
    Parity, 1 Stop Bit */
    outportb(PORT1 + 2 , 0xC7); /* FIFO
    Control Register */
    outportb(PORT1 + 4 , 0x0B); /* Turn on
    DTR, RTS, and OUT2 */
    printf("\nSample Comm's Program. Press ESC to quit \n");

    c = inportb(PORT1 + 5); /* Check to see if
    char has been */
    /* received. */
    if (c & 1)
    ch = inportb(PORT1); /* If so, then get Char */
    } /* Print Char to Screen */

    if (kbhit())
    ch = getch(); /* If key pressed, get Char */
    outportb(PORT1, ch);
    } /* Send Char to Serial Port */
    } while (ch !=27); /* Quit when ESC (ASC 27) is pressed */

    Dibyendu, Jul 10, 2007
    1. Advertisements

  2. snip PC stuff

    I would start off by using a terminal program on the PC, say
    terraterm, so that would rule out a problem on the PC side, and it
    would prove the cable is wired correctly

    martin griffith, Jul 10, 2007
    1. Advertisements

  3. Hi,
    Did you try to look if you have data transfert on your serial line ?
    May be for the PC side you should start to try with a serial instead of
    your untested code ? (like windows hyperterminal or better tera term)
    Re-read your controler datasheet or try to find application notes (often
    availble on chip manufacturer website. Re-read the datasheet part on
    serial controler but not only, look for example if you need to configure
    the pin as a serial line and not as a standard IO, etc.

    Guillaume Chevillot, Jul 10, 2007
  4. Dibyendu

    mc Guest

    What operating system on the PC? What you describe is the DOS way of doing
    it. Under Windows, the ports are controlled by Windows drivers.
    mc, Jul 10, 2007
  5. Dibyendu

    cs_posting Guest

    Yes. And hold something shorting pins 2&3 of the PC cable (transmit
    looped back to receive) to verify that when you short them, anything
    you type is now displayed, or is being displayed twice if it was
    already being displayed once with the pins unshorted.

    Also, if using hyperterminal make sure you set flow control to none.
    cs_posting, Jul 10, 2007
  6. Also, if using hyperterminal... don't. Use something reliable
    like teraterm. ;)
    Grant Edwards, Jul 10, 2007
  7. You haven't specified whether your board includes an RS-232 driver. If
    it does, does it require you to set or clear an enable pin for the

    I would also program a nice long (perhaps 100 millisecond ) delay loop
    between character sends. That will make it much easier to
    track down the problems with an oscilloscope.

    Mark Borgerson
    Mark Borgerson, Jul 10, 2007
  8. Dibyendu

    cs_posting Guest

    Yeah, but when a tool is so widely distributed, even if it's a very
    bad tool, it's worth knowing how to make it perform, because the day
    will come when you run into a situation where your preferred tool
    isn't available - co-worker's machine, customer on the phone, locked-
    down computer, won't let your laptop into the building, whatever.
    cs_posting, Jul 10, 2007
  9. Dibyendu

    Aly Guest


    It could be that the legacy serial port on your PC doesn't work properly.
    I'm having this problem literally right now as we speak.

    My P4 desktop is fine, it's old and clunky, and it's fine. My Dell laptop
    just reads gibberish inbetween odd bits of sense. Ah, I hear you say,
    install a USB<>Serial dongle. Except it won't install as anything lower
    than COM5, due to the infraport spoof ports which are turned off in the BIOS
    yet are still found. That and the internal modem, again, which keeps on
    installing itself.

    I'm using Termrite 1.5. It doesn't need installing and is 74KB in size.
    It's now running on a 486DX2-75 IBM 755C now used for RS232 data capture
    throughout this project.

    I despair!! We've finally reached the age where the indestructable serial
    port doesn't work.

    Aside from that lot it's probably your code but I don't code for the AVR so
    can't tell you. I can only tell you about what's up above.
    Aly, Jul 10, 2007
  10. Dibyendu

    TT_Man Guest

    "> The code for the board:
    Where is EI ? enable interrupts...timer won't run....
    TT_Man, Jul 10, 2007
  11. Dibyendu

    Dibyendu Guest

    I am trying to follow the books of Mazidi, to
    build this board and code also.

    At the first glance I has not find the use of EI. I think I have to
    read more (In depth also). keep in touch.

    Dibyendu, Jul 11, 2007
  12. Dibyendu

    Dibyendu Guest

    Windows XP is my operating system. is it the main problem?? I had
    tried by hyperterminal program first but failed too.
    Dibyendu, Jul 11, 2007
  13. Dibyendu

    Dibyendu Guest

    I am using MAX 232 chip with 22uF electrolyte capacitor, as it
    described on the 8051 Books of Mazidi and max 232 data sheets.

    Waiting for your response.
    Dibyendu, Jul 11, 2007
  14. Dibyendu

    Dibyendu Guest

    This is very good idea I am trying it by today evening. thank you
    Dibyendu, Jul 11, 2007
  15. Of course it will run. It just doesn't produce interrupts...

    Meindert Sprang, Jul 11, 2007
  16. I rarely use hyperterm in dev environment but I couldn't count the
    number of times its saved my arse in the field.. :)
    The Real Andy, Jul 11, 2007
  17. Find out which end is failing first. Use a loopback on your PC (pin 2
    connected to pin 3) and make sure PC is working. Once that is verified
    you know where to look.
    The Real Andy, Jul 11, 2007
  18. Dibyendu

    Dibyendu Guest

    I am fabricate the board for myself.
    Dibyendu, Jul 11, 2007
  19. Dibyendu

    David Brown Guest

    There are also times when you might have to use a cigarette lighter as a
    soldering iron. It might be better than nothing, but it's not exactly
    the tool of choice!

    So the recommendation is to drop hyperterminal if you possibly can, and
    use something simple and decent like Tera Term. Hyperterminal *may*
    work, but why add more uncertainty to your problems?
    David Brown, Jul 11, 2007
  20. Dibyendu

    cs_posting Guest

    To compare the usability of hyperterminal to the utility of a
    cigarette lighter as a soldering iron is rediculous. Compare it to
    some $4 soldering iron from radio shack. Not great, but easy to get a
    hold of and usually practical... even for SMD if you are really really
    cs_posting, Jul 11, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.