open serial port with C

G

Gert B Frobe

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
 
D

dbtid

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
 
E

Emmanuel Delahaye

In said:
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:
 
M

Morris Dovey

Gert said:
> 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
I'd also sugest you specify the serial
protocol required by the EEPROM.
 
T

Thomas Matthews

Gert said:
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
 
A

Alan Balmer

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

Gordon Burditt

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top