open serial port with C

Discussion in 'C Programming' started by Gert B Frobe, Jun 24, 2003.

  1. Gert B Frobe

    Gert B Frobe Guest

    Is it possible to grab the serial port using C? If so, can I control
    each line seperatley? I need to control the serial port in such a way
    to get bit by bit transmission out. I am controlling a serial eeprom
    with the port, at least I want to, and it needs to have each bit
    clocked in. Hence, the bit by bit Tx. So I need to be able to send out
    one bit and clock after that and so on for each bit. Any links or
    example would be appreciated.
    TIA,
    Gert
    Gert B Frobe, Jun 24, 2003
    #1
    1. Advertising

  2. Gert B Frobe

    dbtid Guest

    On 24 Jun 2003 12:41:33 -0700, Gert B Frobe <> wrote:

    > Is it possible to grab the serial port using C? If so, can I control
    > each line seperatley? I need to control the serial port in such a way
    > to get bit by bit transmission out. I am controlling a serial eeprom
    > with the port, at least I want to, and it needs to have each bit
    > clocked in. Hence, the bit by bit Tx. So I need to be able to send out
    > one bit and clock after that and so on for each bit. Any links or
    > example would be appreciated.
    > TIA,
    > Gert
    >


    It's possible to communicate with serial ports in C, but not in a
    system-independent way, b/c it's not coverted by the Standard.

    What OS are you using? Embedded? You might try a ng for that.

    I'm not *quite* sure what you're driving at (no pun intended). You
    normally
    don't program a serial port and toggle the bits that way... you give it
    a byte stream and it handles that.

    If however, you're looking to toggle bits on something that you want
    to *appear* to be a serial port, that's quite another discussion.

    HTH
    dbtid, Jun 24, 2003
    #2
    1. Advertising

  3. In 'comp.lang.c', (Gert B Frobe) wrote:

    > Is it possible to grab the serial port using C? If so, can I control


    Not using standard C. The serial port is generally a device under the control
    of the operating system. Your OS has probably the required functions to deal
    with it. Please repost to a newsgroup dedicated to your platform.

    > each line seperatley? I need to control the serial port in such a way
    > to get bit by bit transmission out. I am controlling a serial eeprom
    > with the port, at least I want to, and it needs to have each bit
    > clocked in. Hence, the bit by bit Tx. So I need to be able to send out
    > one bit and clock after that and so on for each bit. Any links or
    > example would be appreciated.


    In that case, you need some extensions to deal directly with the physical
    memory or the hardware components. Your compiler probably has these
    extensions.

    Details on:

    news:comp.arch.embedded

    --
    -ed- [remove YOURBRA before answering me]
    The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    C-library: http://www.dinkumware.com/htm_cl/index.html
    FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
    Emmanuel Delahaye, Jun 24, 2003
    #3
  4. Gert B Frobe

    Morris Dovey Guest

    Gert B Frobe wrote:
    > I am controlling a serial eeprom with the port, at least I
    > want to, and it needs to have each bit clocked in. Hence, the
    > bit by bit Tx. So I need to be able to send out one bit and
    > clock after that and so on for each bit. Any links or example
    > would be appreciated.


    Gert...

    It's probably possible. I suggest you ask this question in
    news:comp.arch.embedded. I'd also sugest you specify the serial
    protocol required by the EEPROM.

    --
    Morris Dovey
    West Des Moines, Iowa USA
    C links at http://www.iedu.com/c
    Morris Dovey, Jun 24, 2003
    #4
  5. Gert B Frobe wrote:
    > Is it possible to grab the serial port using C?

    Yes, but you need to platform specific, non-portable code.

    > If so, can I control each line seperatley?

    Yes. Most serial ports are character based.

    > I need to control the serial port in such a way
    > to get bit by bit transmission out. I am controlling a serial eeprom
    > with the port, at least I want to, and it needs to have each bit
    > clocked in. Hence, the bit by bit Tx. So I need to be able to send out
    > one bit and clock after that and so on for each bit.

    This is what a UART or USART does. With one of these devices,
    you just place a character into the transmission register and
    it clocks out the bits at the correct speed (baud) as well as
    adding parity (if used) and stop bits.

    > Any links or example would be appreciated.
    > TIA,
    > Gert

    Some processors allow you to output to given pins.
    You need at least two pins: clock and transmit.
    Controlling these pins highly depends on your platform.
    On some, this process involves writing to memory;
    while on others, you have to use specific processor
    instructions (such as writing to a device). An 8051
    processor uses a different scheme than an ARM processor.

    For memory access, just assign a pointer and dereference
    the pointer:
    unsigned char * const Uart_tx_reg = (unsigned char * const) 0x40000;
    *Uart_tx_reg = 'a';
    The receive pointer should be declared as 'volatile'
    since it changes values without the program's knowledge.

    I've had to access serial EEPROMs before, each one
    different depending on how the H/W folks connected
    it.

    --
    Thomas Matthews

    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Thomas Matthews, Jun 24, 2003
    #5
  6. Gert B Frobe

    Alan Balmer Guest

    On Wed, 25 Jun 2003 13:48:25 GMT, Thomas Matthews
    <> wrote:

    >How do _you_ use a _parallel_ port to send _serial_ data?


    By toggling a bit. SOP.

    In fact, for the OP's problem *as described* (not necessarily what he
    *really* wants to do) this is probably easier than using the serial
    port.

    --
    Al Balmer
    Balmer Consulting
    Alan Balmer, Jun 25, 2003
    #6
  7. >How do you know that using a parallel port is the _only_
    >way to do this?


    I'm sure you could do it by manually pushing individual electrons
    around if you really wanted to.

    >What platform are you talking about?
    >How do _you_ use a _parallel_ port to send _serial_ data?


    Bit twiddling and timing. ANSI C doesn't provide a way to do the
    timing, unless you experiment with time-waster loops. If the bits
    to be twiddled are memory-mapped, that's doable, but it takes some
    system-specific magic to figure out where the bits to be twiddled
    are.

    Somewhere I have documentation on how simple hardware (much
    simpler than a modern parallel port) was used on a PDP-8 to
    send and receive data to a bunch (the PDP-8 had a 12-bit word,
    so maybe it handled 12 teletypes per card) of teletypes all at once,
    implementing a "software UART" function.

    A modern RS-232 async serial port with a hardware UART (something
    you connect to serial mouses, modems, etc., and I think this is
    largely independent of platform as long as it's not one from the
    embedded-architecture gang) is probably not adequate for what the
    OP wants:

    1. The clock line required isn't necessarily provided off-chip.
    2. UARTs provide characters with start-stop bits in formats that
    THEY happen to like. (8 and 7-bit characters are common, 6 and
    5-bit characters are sometimes available, and 13-bit characters
    (which, as I recall, was actually used on some kind of military
    radar system) are very difficult to find. If you want NO start or
    stop bits, and just quit clocking when you have no more data for
    the moment, an async serial port is likely to be worse than nothing.

    ><off-topic>
    >A serial EEPROM interface has at least 3 lines, a serial
    >in (SI), serial out (SO) and a clock (CLK). The purpose
    >of the clock line is to latch the value of the SI line
    >into the chip or the SO line out of the chip. If these
    >lines are memory-mapped than the processor can directly
    >access these without having to use a port. This is
    >one instance where a parallel port is not needed.


    In effect, what you are describing *IS* a parallel port.
    One bit in, two bits out, and memory-mapped. You could
    probably control 4 of these interfaces with one modern
    parallel printer port.
    ></off-topic>
    >
    >When making a statment like "... the only way", please
    >include more information that backs up, or proves your
    >statement.


    Gordon L. Burditt
    Gordon Burditt, Jun 25, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pom
    Replies:
    2
    Views:
    1,649
    Bas-i
    Jan 31, 2007
  2. Boki
    Replies:
    0
    Views:
    566
  3. Max Kotasek
    Replies:
    4
    Views:
    978
    Max Kotasek
    Apr 9, 2010
  4. Shadowdancer

    Open/write and read serial port (COM1) on iPAQ 2210

    Shadowdancer, Sep 17, 2004, in forum: ASP .Net Mobile
    Replies:
    1
    Views:
    412
    JuanDG
    Sep 21, 2004
  5. msalerno
    Replies:
    3
    Views:
    409
    Ilmari Karonen
    Jul 14, 2005
Loading...

Share This Page