Sign in to follow this  
Followers 0
Aghaster

Parallel Port and Linux

8 posts in this topic

Hi,

I've just made my own parallel cable embedded into a breadboard for easy programming of chips I can put in my breadboard. Here's a picture:

parallelport.jpg

I made it using an old printer cable which is d25 on the computer end and centronics (36 pins) on the "printer" end. I followed the pinouts from this page and grounded all the ground pins correctly. The problem is that when I try to output something on the data port in a C program, I get a segmentation fault:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/io.h>

#define OUTPUT 0x378 // Parallel port base address
// Each bit of the byte at 0x378 corresponds to a data output pin D0 to D7
#define CONTROL 0x37A // Control pins C0 to C3

int main(int argc, char* argv[])
{
// Check permissions for I/O, usually requires root access
if(ioperm(OUTPUT, 1, 1))
{
printf("Couldn't get the port at %x\n", OUTPUT);
exit(1);
}
if(ioperm(CONTROL, 1, 1))
{
printf("Couldn't get the port at %x\n", CONTROL);
exit(1);
}

// Initial reset
outb(0x0, CONTROL);
outb(0x4, CONTROL);

outb(0xC, OUTPUT);

return 0;
}

I thought maybe it was my C program, so I tried using pyParallel instead, but it also crashes when I try to output something to the data port. I think my parallel port isn't set up correctly in Linux, what should I look for in order to fix this? Thanks

0

Share this post


Link to post
Share on other sites

You can check which modules has attached to which IO port with 'cat /proc/ioport'.

It's been a while since I played with bit banging a parallel port, but this is how I did it back then:

http://jtag-arm9.cvs.sourceforge.net/viewv...amp;view=markup

basically:

init

--

if (ioperm(Port, 3, 1)!=0) {

printf ("ERROR: ioperm(0x%x) failed:\n", Port);

return(-1);

}

--

output

--

outb(JTAG_PWR, Port);

outb(JTAG_PWR | JTAG_TMS | JTAG_CLK, Port);

etc....

--

I also have memories of using a I2C parallel port driver not so long ago, that might give you some more clues.

Cheers,

Mungewell.

0

Share this post


Link to post
Share on other sites
debian:/proc# cat /proc/ioports

0000-001f : dma1

0020-0021 : pic1

0040-0043 : timer0

0050-0053 : timer1

0060-0060 : keyboard

0064-0064 : keyboard

0080-008f : dma page reg

00a0-00a1 : pic2

00c0-00df : dma2

00f0-00ff : fpu

0170-0177 : 0000:00:1f.1

0170-0177 : ICH7

01f0-01f7 : 0000:00:1f.1

01f0-01f7 : ICH7

0290-0297 : pnp 00:08

0376-0376 : 0000:00:1f.1

0376-0376 : ICH7

0378-037a : parport0

037b-037f : parport0

03c0-03df : vga+

03f2-03f5 : floppy

03f6-03f6 : 0000:00:1f.1

03f6-03f6 : ICH7

03f7-03f7 : floppy DIR

03f8-03ff : serial

0400-041f : 0000:00:1f.3

0400-041f : i801_smbus

0480-04bf : 0000:00:1f.0

0480-04bf : pnp 00:09

04d0-04d1 : pnp 00:09

0800-087f : 0000:00:1f.0

0800-087f : pnp 00:09

0800-0803 : ACPI PM1a_EVT_BLK

0804-0805 : ACPI PM1a_CNT_BLK

0808-080b : ACPI PM_TMR

0810-0815 : ACPI CPU throttle

0828-082f : ACPI GPE0_BLK

0860-087f : iTCO_wdt

0cf8-0cff : PCI conf1

9880-988f : 0000:00:1f.2

9880-988f : ata_piix

9c00-9c03 : 0000:00:1f.2

9c00-9c03 : ata_piix

a000-a007 : 0000:00:1f.2

a000-a007 : ata_piix

a080-a083 : 0000:00:1f.2

a080-a083 : ata_piix

a400-a407 : 0000:00:1f.2

a400-a407 : ata_piix

a480-a49f : 0000:00:1d.0

a480-a49f : uhci_hcd

a800-a81f : 0000:00:1d.1

a800-a81f : uhci_hcd

a880-a89f : 0000:00:1d.2

a880-a89f : uhci_hcd

ac00-ac1f : 0000:00:1d.3

ac00-ac1f : uhci_hcd

b000-bfff : PCI Bus 0000:01

bc00-bc7f : 0000:01:00.0

c000-cfff : PCI Bus 0000:02

cc00-cc7f : 0000:02:00.0

cc00-cc7f : ATL1E

d000-efff : PCI Bus 0000:04

dc00-dc0f : 0000:04:01.0

e000-e007 : 0000:04:01.0

e080-e087 : 0000:04:01.0

e400-e407 : 0000:04:01.0

e480-e487 : 0000:04:01.0

e480-e487 : serial

e800-e8ff : 0000:04:00.0

e800-e8ff : 8139too

ec00-ec07 : 0000:04:01.0

ec00-ec07 : serial

ffa0-ffaf : 0000:00:1f.1

ffa0-ffaf : ICH7

Weird, it does appear in the list.

0

Share this post


Link to post
Share on other sites

what happens if you simplify your code and only 'talk' to the OUTPUT port (not the CONTROL port)?

Mungewell.

0

Share this post


Link to post
Share on other sites
what happens if you simplify your code and only 'talk' to the OUTPUT port (not the CONTROL port)?

Mungewell.

I've just tried it, it also causes a segmentation fault. Could it be because of something I haven't wired properly? I'm sure that I've grounded all the ground pins, I've double checked them.

0

Share this post


Link to post
Share on other sites

I did something similar until I realized that the parallel port was hopeless. It's fine for messing around, and can still interface with many chips, but anything that requires timing at all will be difficult on a modern OS. Also, the shortest pulses I could get were quite long and erratic. An Arduino is cheap, go that way instead :P

0

Share this post


Link to post
Share on other sites
I did something similar until I realized that the parallel port was hopeless. It's fine for messing around, and can still interface with many chips, but anything that requires timing at all will be difficult on a modern OS. Also, the shortest pulses I could get were quite long and erratic. An Arduino is cheap, go that way instead :P

I've heard about the Arduino, it really looks cool, but it seems to come in many different versions. Which one would you recommend?

0

Share this post


Link to post
Share on other sites

The official one is easiest to jump into. You just plug it in, compile some code with the Arduino IDE and it works. There are some that are cheaper, more powerful, come in different form factors (such as one that plugs right into breadboard), but since it's an open platform it should all work just the same. It should all work the same, expect some minor bumps if you go with different hardware, nothing you can't handle though.

For interfacing with breadboard, make sure you have some nice stranded wire with breadboard tips. These jumper wires can be gotten for next to nothing from Asia on ebay. Like this.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0