Bekijk de volledige versie : LPT thermometer
Hello,
I'd like to connect some I2C thermometer chip to parallel port of WL500g, but so far I've no idea about low-level control of specific LPT pins in WL500g. Is there some example code to toggle and read ASUS parallel port pins?
KillerOPS
02-05-2005, 19:51
I am looking for this for about two weeks with no answer (how to control the LPT of that f***ing thing).
No answers yet.
Just use generic parallel port ioctls, that's it. But remember to remove lp.o module first.
Just use generic parallel port ioctls, that's it. But remember to remove lp.o module first.
Oleg, would You (or somebody else) please compile _simple_ LPT ioctl binary program, that can be called with additional parameters from command line?
Something like:
lptioctl port_no bit_no value
and:
lptioctl port_no bit_no
(where return value = bit state)
Then it will be quite easy (at least for me) to write simple shell script for I2C or anything else.
KillerOPS
02-05-2005, 23:35
Yes, that would be more than helpful. I would like to see the source also.
My idea about that is something like this
./lptioctl (portnumber) send (number)
./lptioctl (portnumber) read
=> returns a byte
KillerOPS
03-05-2005, 15:38
this is where i got:
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#define base 0xBF800010
static void parport_write_data(unsigned char d) {
unsigned char *io = (unsigned char *) base;
*io = d;
}
static unsigned char parport_read_data() {
unsigned char *io = (unsigned char *) base;
return *io;
}
static unsigned char parport_read_status()
{
unsigned char *io = (unsigned char *) base;
return *(io+1);
}
static int LPTInit()
{
check_mem_region(base, 3)
}
static void parport_splink_unregister_port()
{
release_mem_region(base, 3);
}
int main()
{
if (LPTInit())
{
int i;
for (i=0;i<10000;i++) {
parport_write_data(254);
usleep(10000);
parport_write_data(1);
usleep(10000);
}
}
}
[quote]
i'm compiling it with
[quote]
mipsel-uclibc-gcc -o p.c
This thing should blink some data pins on the lpt port, right? But it doesn't. It just gives me a nice Segmentation Fault.
I removed all the lpt stuff from the firmware (modules, lpd and l910...) (in fact it's a 10gig hdd partition)
What i've done wrong?
Use iopl(3) to get an access.
In fact you will probably need to mmap this memory first to get an access to it.
KillerOPS
03-05-2005, 15:47
please give me an example.
Check this code for the general mmap code sample:
http://wl500g.info/attachment.php?attachmentid=171
Most likely you will need to change 0xBF800010 to 0x1F800010; mmap 0x1F800000 (aligned), then access +0x10.
KillerOPS
03-05-2005, 16:23
lost myself there :( :confused:
void *map;
unsigned char *base;
int fd = open("/dev/mem", O_RDWR);
if (fd < 0) {
perror("/dev/mem");
return 1;
}
map = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0x1f800000);
if (map == NULL) {
perror("mmap");
return 1;
}
printf("Device memory mapped ok\n");
base = ((unsigned char *)map) + 0x10;
KillerOPS
03-05-2005, 17:15
No positive results yet.
I looked at parport_splink.c file and i extracted from there the things i thought are used for writing to the port. However, that's without mmap and things like that. But that doesn't work also. I believe that the compile command-line is not right also. Any ideas?
Oleg, your code only maps the memory, right? Then i have to writeb() at base? Or do i need to do more complex things?
There is a similar thread on Q&A where someone apparently did a module for controlling the LPT. I think i'll wait for his reply because it states that the module works.
In the end, it sounds that it's really rocket science to blink those d**n data lines.
no, just compile as usual. no writeb is needed.
KillerOPS
03-05-2005, 20:04
can you post a complete example (.c) which blinks the data lines with a 1 sec interval? And which command should i use to compile it?
That would be more than helpful :)
ps: with this wl500g i realised that embedded programming is not that easy as x86 :(
KillerOPS
04-05-2005, 12:40
Any idea? Anyone?
* parport_fs.c, module to give access to a memory region like the gpio device
* Author : Florian Schneider, very hacked up version
* Example, No support, worked on the 1.7.5 oleg release
* Put this in drivers/parport add to the Makefile to compile
All,
Readed the source code again, i putted some very specific code which i needed, you might want to modify
xgpio_init() and xgpio_write()
I used it to control a stepper.
I don't know if it compiles under the current source releases. (Haven't created the latest build env yet)
Regards
Zolf
Didn't get a working environment yet,
But to compile the module do the following
Install the ASUS GPL 1927 tar gz
Go to the src/linux/linux/drivers/parport directory
copy parport_fs.c into it
Modify the Makefile
add a line
obj-$(CONFIG_PARPORT_FS) += parport_fs.o
modify the line
parport-objs := share.o ...........
into
parport-objs := parport_fs.o
Enable parport Module support in the kernel
Haven't tested it but it seems to compile
Hello,
with this example code you can directly access the printer port pins.
You must have the toolchan installed to compile.
Compile with ./build.sh
If someone knows how to avoid static linking, please let me know.
Martin
Hi Martins,
I compiled successfully myport but oleg_fn() fails, it quits with "User defined signal 1". I'm running 1.9.2.7-7c.
I assume you're using the parport_fs mentioned above. Did you compile it for this firmware version? Any modification?
Will it run with an USB to parallel adapter?
Thanks,
MatB
Hi MatB;
the last time i testet "myport" was with oleg's firmware 1.9.2.7-6c.
I had no problems then.
I didnt make any modifications tho oleg's firmware.
I just copied the bin file to my USB stick and started from there:
cd /tmp/harddisk/myport
./myport
I have already udatet to oleg's latest fw (1.9.2.7-6c), but not tested "myport" again.
I will do that on weekend an report the results here.
Did you also test the "myport" binary that i compiled (from the tar file)?
Martin
Did you also test the "myport" binary that i compiled (from the tar file)?
Martin
Sure i did. I think the problem is that i'm using an external USB to parallel adaptor, since i have the gx version without parallel port.
Also the memory mapping could be wrong, since the gx has 16 megs more.
Bad luck.
Hi MatB,
can you tell me the brand and model of your USB to parallel port adaptor?
Some time ago i wrote a software that talks to the "iowarrior" (USB I/O-chip from codemercs) from userspace. This sw reads/writes the portpins and writes to the LCD display connected to the iowarrior.
I used FIFO's do do the communication: shell->application->USB(iowarrior)->LCD.
Perhaps i can do the same for an USB2LPT adaptor.
Kind regards,
Martin
Hi MatB,
can you tell me the brand and model of your USB to parallel port adaptor?
Here's what i get in the syslog:
May 5 18:20:09 kernel: printer.c: usblp0: USB Bidirectional printer dev 6 if 0 alt 0 proto 2 vid 0x4348 pid 0x5584
May 5 18:20:09 kernel: printer.c: usblp0 Device ID string [0]=''
I bought this cheap USB to parallel on ebay for 10 euros, the box says "WahTeng WT-001".
Some time ago i wrote a software that talks to the "iowarrior" (USB I/O-chip from codemercs) from userspace. This sw reads/writes the portpins and writes to the LCD display connected to the iowarrior.
I used FIFO's do do the communication: shell->application->USB(iowarrior)->LCD.
Perhaps i can do the same for an USB2LPT adaptor.
That would be great!
My idea is to use libusb (which is available as package) but i could not find specs about the protocol of this device.
Hi MatB,
I bought myself an USB to RS232/LPT adaptor.
It has the MOSCHIP MSC7715 inside (one RS232 and one LPT interface).
With the example code usb2lpt you can access the portpins from userspace.
Open the poject with kdevelop or compile with make from command line.
To compile for MIPS (WL-500) take a look at the Makefile and (un)comment the related defines.
I had no time to test on Asus so far, but it should work.
Consult the PDF dokument from MOSCHIP to adopt the sourcecode to your USB interface.
Kind regards,
Martin
Hi MatB,
I tested usb2lpt with my Asusu WL-500g (see attached file).
Have the toolchain installed and (re)compile with ./bulid.sh.
Martin
Hi MatB,
I tested usb2lpt with my Asusu WL-500g (see attached file).
Have the toolchain installed and (re)compile with ./bulid.sh.
Martin
I uploaded mcs7715.o and issued command: insmod mcs7715 and got:
insmod: unresolved symbol _gp_disp
insmod: unresolved symbol printf
can anyone tell what is wrong?:confused:
@martins: thanks, i'll give it a try in the next days!
Hi MoD,
"mcs7715.o" is not a kernel module! It is just the objekt file of "mcs7715.c".
Therefore you can't insmod "mcs7715.o".
The intetion of usb2lpt was to access a usb device from userpace (via usbdevfs) without the need of a special usb device driver.
Just copy usb2lpt (the executable) to your usb stick and start it from there:
cd /tmp/harddisk
./usb2lpt
Kind regards,
Martin
Could anyone help me with how to compile a moscip module? There is a driver source:
http://www.moschip.com/data/products/MCS7715/Linux_7715.tar.gz
I would like to use LPT port to connect a printer. I guess it would be usefull for this community.
Hi MoD,
the source and makefile you refer to is for kernel series 2.6.
I can help you if you want tro compile for that kernel version.
But you could also just read the readme file.
If you want to (cross)compile for the asus i can't help you.
Martin
has anyone a solution how to setz port pins HIGH and LOW with "WahTeng WT-001" USB -> LPT Konverter with ASUS WL-500g Premium?
Florian
can you guys tell me where can i buy an usb -> lpt adapter with MOSCHIP MSC7715 Chip?
Greets
Florian
Hello,
with this example code you can directly access the printer port pins.
You must have the toolchan installed to compile.
Compile with ./build.sh
If someone knows how to avoid static linking, please let me know.
Martin
Thx for themyport example code. I compiled it an run it on latest supported oleg firmware for asus wl-500g.
Now my problem is to find out on how could i set the 8 datapins on LPT to high / low. i find out to set one port to high with setting
parport_write_data(100, base);
and set the same port to low with
parport_write_data(112, base);
but how could i set the other 7 data pins?
Greets
Florian
Hi Florian,
you can set/clear the data lines this way:
(with bitnum from 0 to 7)
void set_pin(unsigned char bitnum)
{
unsigned char port_val, port_mask = 0x01;
port_val = parport_read_data(base); // read the portlines to port_val
port_val |= (port_mask << bitnum); // set the bit in port_val
parport_write_data(port_val, base); // write back port_val
}
void clear_pin(unsigned char bitnumber)
{
unsigned char port_val, port_mask =0x01;
port_val = parport_read_data(base); // read the portlines to port_val
port_val &= ~(mask << bitnum); // clear the bit in port_val to 1
parport_write_data(port_val, base); // write back port_val
}
Or the same in one line:
Set portline:
parport_write_data(parport_read_data(base)|=(0x1<<bitnum),base);
Clear portline:
parport_write_data(parport_read_data(base)&= ~(0x1<<bitnum),base);
Martin
ok thanks i will try it later ;) and give a report.
now i have inserted your functions but i don't know how to use them.
void set_pin(unsigned char bitnum, unsigned char* base)
{
unsigned char port_val, port_mask = 0x01;
port_val = parport_read_data(base); // read the portlines to port_val
port_val |= (port_mask << bitnum); // set the bit in port_val
parport_write_data(port_val, base); // write back port_val
}
void clear_pin(unsigned char bitnum, unsigned char* base)
{
unsigned char port_val, port_mask =0x01;
port_val = parport_read_data(base); // read the portlines to port_val
port_val &= ~(port_mask << bitnum); // clear the bit in port_val to 1
parport_write_data(port_val, base); // write back port_val
}
when i try the following nothing happens:
unsigned char bitnum=2; // 0 to 7 right?
set_pin(bitnum,base);
printf("Pin ON\n");
usleep(5000);
what i've been doing wrong?
sorry for my stupid question but i'm not so fit in c.
Hi Florian,
make sure that you have initialized the pointer "base" ( base = oleg_fn() ) before you use it.
Check your programm for the correct use of pointers and dereferenced pointers.
Martin
hm i think thats all right. Here's my main function. Its nearly the same like in your myport source. the rest of the code is the same too.
is the following the problem: unsigned char bitnum='3'; ??
int main(int argc, char *argv[])
{
int i;
unsigned char *base=NULL;
base = oleg_fn();
if(base==NULL) return 1;
unsigned char bitnum='3';
set_pin(bitnum,base);
printf("Pin ON\n");
usleep(5000);
printf("Fertig\n");
return 0;
}
Hi Florian,
Change the expression "unsigned char bitnum='3';" to "unsigned char bitnum=3;" and your program should work as expected.
Martin
ok thx it works but i wonder why only port 4 and 6 works as well. maybe i try first to connect 8 LEDS to parallel port insted of my radio Power jack remote.