Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > open serial port with C

Reply
Thread Tools

open serial port with C

 
 
Gert B Frobe
Guest
Posts: n/a
 
      06-24-2003
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
 
Reply With Quote
 
 
 
 
dbtid
Guest
Posts: n/a
 
      06-24-2003
On 24 Jun 2003 12:41:33 -0700, Gert B Frobe <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      06-24-2003
In 'comp.lang.c', http://www.velocityreviews.com/forums/(E-Mail Removed) (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- (E-Mail Removed) [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/
 
Reply With Quote
 
Morris Dovey
Guest
Posts: n/a
 
      06-24-2003
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

 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      06-24-2003
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

 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      06-25-2003
On Wed, 25 Jun 2003 13:48:25 GMT, Thomas Matthews
<(E-Mail Removed)> 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
(E-Mail Removed)
 
Reply With Quote
 
Gordon Burditt
Guest
Posts: n/a
 
      06-25-2003
>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
emulate a serial port in windows (create a virtual 'com' port) Pom Python 2 01-31-2007 07:49 PM
Serial Port(COM)Port Saref Aref Computer Information 2 02-14-2005 07:38 AM
Can I connect router Serial interface directly to a PC serial port? Faustino Dina Cisco 2 08-18-2004 02:30 AM
Re: Serial port and PS/2 port schematics OR Assistive Tech. suggestion naive.verizon@locality.net Computer Support 1 07-10-2003 11:46 AM
Re: Serial port and PS/2 port schematics °Mike° Computer Support 1 07-09-2003 10:30 PM



Advertisments