Ruth Hendrix

Printer Interfacing

Discussion created by Ruth Hendrix Employee on Jan 28, 2006
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
Posted: Thu Dec 29, 2005 7:54 am    
Hi everyone !

Does anybody know, or have an idea, how I can interface
an HCS12 based embedded system to a modern printer (any
low cost printer suits me), possibly through a USB link.

Posted: Thu Dec 29, 2005 8:42 am    

for an USB Printer you need an USB Host controller. There is no HCS12 with an USB Host controller. A serial or parallel printer can be interfaced by using the SCI or bitbanging. Another option is to use a Network Printer with a NE64 but you have to do all the LPD/LPR network protokol stuff.

Posted: Thu Dec 29, 2005 3:32 pm    

I've interfaced many embedded controllers to printers. In terms of hardware the interface requires a minimum of approx. 2 8-bit ports, one of which can be configured as outputs only, the other configured as 4 inputs and 4 outputs (the control & status port). In addition, you'll need buffering hardware to drive the printer cable. My most recent design used an integrated IEEE-1284 IC which is cheap ($2.50) and works very well (Fairchild 74lvx161284).

Finally, when you have all that you need to write a printer driver. Again, this isn't terribly difficult. I have snippets of assembly code that can be made available.

Posted: Thu Dec 29, 2005 7:59 pm    

Hello, and thanks to you both.
The thing is, I'm talking about a modern low cost printer,
meaning a USB interface. While for the hardware, there are several
possible solutions, like the RS-232 to USB modules etc. , the problem seems to be in implementing the software interface. Unless... there's something I'm missing. Any more ideas ???

Posted: Sat Dec 31, 2005 5:13 pm    

The software required to "drive" a printer isn't terribly difficult (this includes "modern' printers such as the latest ink-jets & laser printers). They all respond to standard printer commands, such as "form-feed" (load a page) (eject a page), carriage-return, line-feed, ets.
In addition, if you want to use the more exotic stuff like Escape-sequences you can find information on the net. I have.

Perhaps I'm not understanding where your problem is.


Posted: Sun Jan 01, 2006 10:04 pm    

Hi Ron, and thanks for your answer.
Well, maybe I'm missing something (apparently).
I can summarize the problems in 2 sentences:
1. handling the USB interface.
2. Driving the printer. I don't know their "language". Do you think
(or know) with USB it's the same as with the parallel port ?
Maybe you can direct me to some material about that - I'd appreciate
it very much.

Posted: Mon Jan 02, 2006 1:25 pm    

Now I think I understand; I can address at least part of your concerns.
First, I've used USB to serial converters and I think this is not what you need. They tend to convert FROM USB to Serial, not the other way round (note: I'm not an expert here, there may well be devices that do what you want).

Now on the printer driver: printers just want to see ASCII text with minimal controls. This is roughly what to do:
1. Put your text to be printed into a buffer of some size
2. You have to provide control characters to the printer. You can either integrate them into your text buffer which makes your "buffer-creator" more complex and your actual driver simpler, or you can keep your text buffer pure and have the driver provide them "on-the-fly". Either way the first thing to send to the printer is a 0x0C (form-feed/new page). Then start sending the text buffer a character at a time. If your print-out is to be 80 chars wide then you have to send a carriage-return / line-feed (cr/lf) after each block of 80 chars. This is simply 0x0D /0x0A.
3. You should keep track of how many lines you've sent. After each "n" lines of text you should send another form-feed (0x0C) to load a new page.
4. When you've finished you should send a final form-feed to kick out your last page.

I hope this helps.

Posted: Tue Jan 03, 2006 9:30 am    

Hi Ron ! Thanks again for your answer.

Well, your answer is helpfull. I didn't have any experience with
printers or USB, so I needed some directions.
About the USB - I thought those converters are bidirectional. If that's not the case, I guess it complicates the design. I'll have to look more carefully into it.
About printers - thanks for the info. I also found a whole API to HP printers (called APDK), written in C++, in HP developers site. Have you worked with this one ? I'll have to study this one also.

Best Regards,

Posted: Tue Jan 03, 2006 2:41 pm    

I hope someone makes a serial/usb device that does what you want. If you find one pls let everyone know.
I have some experience at -NOT- making usb work; my current opinion of usb is that it was designed by a committe of creatures that didn't have enough brain-cells to rub together. It is simply the worst-designed communications architecture I've ever seen.

Good news on your HP driver find. Study it, extract what you need and move on down the road.

Good luck with your project.

Posted: Tue Jan 03, 2006 3:55 pm    

Thanks for your answer.

If I have any new interesting findings, I'll let everyone know. Since you've got a lot of experience, Maybe we'll talk again, when I get to deal with actual bits and bytes.

Thanks, again, for your help.