open serial port with C 
Author Message
 open serial port with C

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


Sun, 11 Dec 2005 03:41:33 GMT  
 open serial port with C

Quote:
> 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



Sun, 11 Dec 2005 03:59:08 GMT  
 open serial port with C

Quote:
> 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.

Quote:
> 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:


--

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/



Sun, 11 Dec 2005 04:17:10 GMT  
 open serial port with C

Quote:

> Is it possible to grab the serial port using C?

Yes.

Quote:
> If so, can I control each line separately?

Yes.

Quote:
> 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.

I've done this many times before.
It's not hard.

Quote:
>  Any links or example would be appreciated.

You can do anything with C.
The question is what your operating system will allow you to do.
Please tell us what hardware and operating system you are using
so that we can direct you to the appropriate forum
for architecture and operating specific questions.
Of course, we will be happy to answer questions
about the C computer programming language
here in the comp.lang.c newsgroup.


Sun, 11 Dec 2005 04:28:19 GMT  
 open serial port with C
 > 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

protocol required by the EEPROM.

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c



Sun, 11 Dec 2005 05:30:44 GMT  
 open serial port with C
Quote:

> Is it possible to grab the serial port using C?

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

Quote:
> If so, can I control each line seperatley?

Yes.  Most serial ports are character based.

Quote:
> 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.

Quote:
> 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



Sun, 11 Dec 2005 05:50:11 GMT  
 open serial port with C
actually, using the parallel port is the only way to do this.


Quote:
> 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



Sun, 11 Dec 2005 09:49:14 GMT  
 open serial port with C

Quote:

> actually, using the parallel port is the only way to do this.


>>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

How do you know that using a parallel port is the _only_
way to do this?
What platform are you talking about?
How do _you_ use a _parallel_ port to send _serial_ data?

<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.
</off-topic>

When making a statment like "... the only way", please
include more information that backs up, or proves your
statement.

--
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



Sun, 11 Dec 2005 21:48:25 GMT  
 open serial port with C
On Wed, 25 Jun 2003 13:48:25 GMT, Thomas Matthews

Quote:

>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



Mon, 12 Dec 2005 00:25:09 GMT  
 open serial port with C

Quote:
>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.

Quote:
>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.

Quote:
><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.

Quote:
></off-topic>

>When making a statment like "... the only way", please
>include more information that backs up, or proves your
>statement.

                                        Gordon L. Burditt


Mon, 12 Dec 2005 03:45:45 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. I want open the COM1 Port (serial Port)

2. Serial port to serial port copying software

3. Challenge: Virtual serial ports from real serial port

4. opening serial ports above 9 using CreateFile

5. Serial Port Com10 can't be open

6. How to open serial port in Win2000?

7. HELP!!! Opening Serial Ports through VC 6.0

8. Opening multiple serial ports

9. How can I check carrier status on an open serial port

10. URGENT-Opening a serial port

11. Serial.cs

12. The real serial.cs

 

 
Powered by phpBB® Forum Software