I Want to Write Program to Actual External Hardware Through C

R

Thread Starter

R.BABU

while writing a program in C for getting output signal from serial port I am not getting any signal. Instead of making my external circit board I checked the voltages in the across serial port pin 3 and pin 5. no voltage. Can any one help. It always shows 11.2 volts. why? Am I making a mistake.
 
<p>This issue is divided into two independent parts. The first is whether your application is allowed to write directly to the hardware. If you are using a protected operating system such as Windows or Linux, then, in general, a user mode application can not write directly to the hardware. This is done to prevent an application from accidentally "crashing" the operating system.

<p>If you are using a non-protected environment, such as DOS, then you should be able to write directly to the hardware. In this case, since you are seeing 11.2 volts between pins 3 and 5 (transmit and ground on a DB9), then it means you are not transmitting (since this is the normal RS-232 marking condition). To set a UART to transmit requires a few steps:

<p>This example assumes the base address of the 8 byte I/O space for the card is 0x300 (300 Hex). If your address is different, simply replace it with your address.
<pre>
baseaddress = 0x300;
_outp(baseaddress + 3 , 0x80); // Setting the high order bit of the LCR register enables write access to the "Dividor Latch Register"
_outp(baseaddress , 0x01); // This writes the low order byte of the divisor to the DLL (Divisor least significant byte)
_outp(baseaddress+1 , 0x00); // This writes the high otder byte of the Divisor to the DLM
//
//Note that the above sets the UART to its highest possible speed. The divisor is calculates as the (oscillator frequency) / 16 / divisot. Since the "normal" default
//oscillator is 1843200 Hz, then the data rate would be 1843200 / 16 / 1 = 115200 baud
//
_outp(baseaddress + 3 , 0x33); // This turns off access to the Divisor Latch Register and set the chip for 8 data bits, 1 stop bit, and no parity

// In general, at this point, you should make sure the transmitter is empty and ready to accept another character by checking bits bit D5 of baseaddress + 5 (LSR)

_outp(baseaddress , 0x55); // This will actually write a hex 55 (binary 01010101) battern out on pint 3
</pre>
<p>The above description assumes you are not using any FIFO on the chips and is about the simplest test possible. For further information on the UART registers, you can download the specs from either the EXAR web site (http://www.EXAR.com), the Oxford web site (http://www.OXSEMI.com), TI web site (http://www.TI.com), or National web sites (http://www.NATIONAL.com).

<p>Sealevel (www.SEALEVEL.com) includes C++ and VB demos and code samples with their serial interface products, in case you need additional serial ports.
 
C

Curt Wuollet

There is a mechanism to allow user programs access by granting root permission only for the operations required in Linux. But in almost any OS, direct control of the hardware is a bad idea for the reason that other programs know nothing about it, among others. Except on ancient PCs, the overhead of doing it right is pretty insignificant and you avoid problems that are extremely
difficult to diagnose. And at least with Linux there is full visibility of the driver and you can pare it down to do only what you want, in effect moving some of your solution there. Your program becomes simpler and generic as it talks to a file.

Regards

cww
 
L
Follow some of the steps below which could trouble shoot your problem.

1. Is the baud rate on both the systems same? if not maintain the baud rate balanced on both the systems. Remember it also depends on the system configuration;

2. Are you using bioscom function (defined in bios.h) for passing data? If so then check whether the port has been initialised on both the systems.

Please mail me if the problem still persists.
 
Top