Output to Parallel Port

Hello,

I am trying to use my parallel port to talk with external hardware (ADC0804). I cannot send simple output to the data-register of the parallel port. Here is the code I am using:

#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <hw/inout.h>
#include <sys/neutrino.h>
#include <sys/mman.h>

#define PORT_LENGTH 1

#define DATA_ADDRESS 0x378
#define CTRL_ADDRESS 0x37a
#define INIT_BIT 0x04
#define LOW 0x00
#define HIGH 0xFF
#define MAX_COUNT 60

int main( )
{
int privity_err,count;
uintptr_t ctrl_handle, data_handle;

privity_err = ThreadCtl( _NTO_TCTL_IO, NULL );
if ( privity_err == -1 )
{
	fprintf( stderr, "can't get root permissions\n" );
	return -1;
}

ctrl_handle = mmap_device_io( PORT_LENGTH, CTRL_ADDRESS );
out8( ctrl_handle, INIT_BIT );

data_handle = mmap_device_io( PORT_LENGTH, DATA_ADDRESS );

for ( count = 0; count < MAX_COUNT; count++ )
{	
	out8( data_handle, LOW );
	printf( "Low\n" );
	sleep( 1 );

	out8( data_handle, HIGH );
	printf( "High\n" );
	sleep( 1 );
}
return 0;

}

For some reason, when I read the voltage on the data-pins with a multimeter, they never change! Can any suggestion a solution?

Thank you.
Matt.

I could be wrong, but I think the 0x04 INIT bit you are setting is the Bi-Directional bit. Setting this bit means you want to read data from the cable, not send data to it.

I have some success…But wait.
I don’t send any configuration to the port, all i send is out8(0x378,0xaa), and it properly sets the data bits. However, when I add two lines, say

out8(0x378,0xaa);
sleep(1);
out8(0x378,0xff);

nothing happens, the lines remain at 0xaa. I have “slay devc-par” and nothing seems to allow more than one call to the parallel port. any ideas? The status register is always at 0x7F, while the control is always at 0xc6.

Please see my other posting on ECP vs. NORMAL, Bi, and EPP.

I seem to have better success now that I have changed my port settings in the BIOS. However, the settings are a little confusing. I am using a P3 Compaq 500Hz PC, and within the BIOS, there are a few options, not immediately clear to me. I can change the Onboard Device Options, and the Printer Mode.

In Printer Mode, I have options of (Standard) or (Flexible) or (Output-Only). How do these relate back to SPP, Bi, ECP and EPP???

In Device Options, I can set memory locations, along with DMA settings. These are some examples:
(378-37A, 778-77D, IRQ 9)
(378-37A, 778-77D, IRQ 10)
(378-37A, 778-77D, IRQ 7, DMA 3)
(378-37A, 778-77D, IRQ 9, DMA 3)
Is the DMA only used in EPP mode?

Thanks for any help on this clarification, I cannot find anything on the web.

The people who made this computer must be demented. Oh, you mentioned it was Compaq, so that is redundant.

Usually “SPP” which is output-only is called “standard”.
Output-Only should work fine.
I’ll bet their “Standard” is really Bidirectional. The best way to check
is to see if toggling the 5 (0x20) or 7 (0x80) stops output. While some ports use 5, there are some that use 7.

Flexible, who knows? Maybe ECP? Usually with ECP you have to choose a DMA channel. Try writing to and then reading from port base+3.
If you get something back, it is probably EPP. For ECP read at base+ 0x402 and see if you get something other than 0xff.

EPP does not use DMA, but ECP does.

It appears that “standard” is the bidirectional state since I am able to input values to the data port when I write 0x20 to the control port, while outputting values when i write 0x00 to the control. One thing however, is that when I do output 0x20 to the port, the port control port gives me the proper behaviour, however, when i read its value, it doesn’t retain the value of 0x20. For example, i wrote 0x20 to the port, and read back 0xe0. Or, I write 0xab and read back 0xeb.

Another quick question. I am trying to interface the parallel port to an ADC, and I was just going to use the Bi-directional mode. Is it much more trouble to use the ECP mode, seing as it can handle much quicker speeds?

I think that bit set to output more are not readable (not will not read what you wrote)

Wow, openqnx.com is not friendly. First I accidentally posted a reply, and next it won’t let me edit it. Snarl.

Well let me be brief this time. The bi-directional parallel port can move data up to about 3MegaBytes per second. A recent modern port should be able to do this. This is pretty darn fast. In ECP mode, you get some benifits. There’s a FIFO buffer, DMA transfers, and RRL expansion if you are reading data. This will no doubt take more work. How much, I don’t know. I’ve never written any ECP code. Frankly I’d rather chew razor blades then figure out hardware designed by the big MS. You may feel otherwise.