PDA

View Full Version : PIC18xxx to USB device ?



Felch
- 19th August 2005, 18:58
Hi, PIC gurus!

I have to read a smart-card reader (Estonian ID-card, smth. like a passport). I did find out how to command the reader and how to make it send all unprotected data but...via com port. No i would like to move on to USB readers since comm-devices seem to getting obsolate. After some search i found Microchip's code examples but they all communicate to "the opposite direction" - PIC to PC. I would like to have a PIC talking to USB card-reader.
Anybody working with similar project? Could there be any code examples available?

Thnx!
/Felch

Some more reading and i found in the data comms forum that this kind of communication is considered impossible. May-be...but PIC has all needed hardware. So perhaps it's Basic that lacks USB routines? Or is it really impossible?

Sorry for posting to wrong phorum, perhaps admins could move the thread.

Darrel Taylor
- 20th August 2005, 21:35
Hi Felch,

Not impossible. But as I'm sure you've already read, the PIC must act as a HOST to the USB bus. Not an easy thing to do.

Check out this device from GHI. Crownhill is now the European distributor for it too.

http://www.crownhill.co.uk/product.php?prod=1459

It's still in beta right now, but GHI seems to be working hard on it. I just bought 1 myself (received it yesterday) so I'm not much help for sample code at the moment.
<br>

Felch
- 23rd August 2005, 18:10
Thanks for advice! I understand that it might be difficult to programm PIC acting as an USB host. I am just wondering, could it be possible at all (does it have needed hardware ?). I know that an AVR processor has been put working with USB (Mycke Predko, the Girder device) but it did not need a host.
Surely special chips would make life much easier. I will try this chip for sure.

Darrel Taylor
- 24th August 2005, 06:15
Well, I've learned to "Never say Never", because some 15 year old genius will come along and figure a way to do it.

However, everything I've found so far, says NO. There are 2 parts to the "Physical Layer" of USB. &nbsp;Physical layer generaly means hardware, but since we work with PIC's, we know that many types of hardware can be simulated.&nbsp; But, only 1 of those 2 components are present in any of the current PIC's.

SIE - Serial Interface Engine. This is what is in a USB capable PIC chip. It's the same on both the Host and End device. So in effect, any 2 devices can communicate with each other without having a Host Controller, as long as it is NEVER actually connected to a REAL USB bus. &nbsp;Being a Half-Duplex system, you are also limited to a Master/Slave arrangement.<br>

HC - Host Controller. This is the part that's lacking in PIC's. It's function goes something like this. "initiates transactions and controls access to the USB. It divides the time into “frames” and issues a start-of-frame (SOF) packet at each frame interval. In addition, it processes requests for data to and from the host and handles errors."

That makes it sound like you should be able to simulate it in software, but I think that things just happen too fast to be able to do it all in real time. Throw on top of that the "Protocol Engine Layer" and the "Application Layer", and there's just not enough time to do it all.

Now add the fact that the largest PIC with USB only has 16K words of program space, and you can see why I bought the USBwiz.

Refs:
USB Behind the Scenes: Understanding the Technology (http://digital.ni.com/worldwide/bwcontent.nsf/web/all/EB6A8621ACAB7E0786256EE400826C17)
How USB Works (http://www.tech-pro.net/intro_usb.html)

<br>

Felch
- 24th August 2005, 08:10
Thanks for a very thorough answer. Exactly what I needed.

Demon
- 9th January 2006, 04:47
Why not read the smart card directly? Don't use a reader at all?

I've seen an example by Myke Predko (sorry on spelling if wrong), but he used his own BASIC language. He has one example using FAT16, and another just doing generic access.

I'm still looking for an example using PIC Basic Pro though. I wanted to do this myself.

Robert
:)

Demon
- 9th January 2006, 05:00
Or, an acrobatic way around the PIC limitation of being only a slave:

- connect PIC to PC as USB slave.
- connect card reader to PC as USB slave.
- have PIC tell PC to access card reader and send info back to PIC.

Robert
:)

Felch
- 9th January 2006, 07:38
Can't read it directly because ia wanted to have an industrial reader (nice look etc, you know). One option is of course replacing industrial readers electronics with mine (i developed code that reads ID-card directly) but ... i was just wondering if there are easier ways.