0
\$\begingroup\$

I have been designing PIC based systems for several years, but this will be the first time that I am involved in a project based on USB communication. I don't exactly know where to start but I have been searching around the internet for a few days for "PIC USB tutorials". Unfortunately I could not see any information for my situation.

I need to design a system which will have "only one USB port" to connect to PC (in order to pass some logging information to PC) and also a "USB flash memory" to save some data. Of course, these connections can not be created at the same time since there is only one slot. But my system should sense which is connected and behave in a proper way. Is it possible to create a system like this? What kind of electrical designations should I consider? And some guidance links for a starter will be appreciated.

\$\endgroup\$
  • \$\begingroup\$ You should look into the use of the USBID pin, or use a USB serial chip (FT232 say) for the PC communications. \$\endgroup\$ – Majenko Sep 24 '14 at 8:19
  • \$\begingroup\$ Which kind of PIC do you use commonly? Which family? \$\endgroup\$ – Majenko Sep 24 '14 at 9:17
  • \$\begingroup\$ I have been using PIC18F87K22 for the last 2 or 3 projects. But in this Project, i have to be faster in the design since a tft screen should be driven and many measurements should be made. So, i am planning to use a PIC32 which has a clock max frequency of 200 MHz. I do not know what is USBID pin because i am planning to use a USB connector which is also found in PCs or laptops. Because i have to connect a USB flash(thumb drive). So, as i know i only have 4 pins(2 for power and D- , D+). Thanks for your advice. \$\endgroup\$ – hayat_bilgisi Sep 25 '14 at 6:40
2
\$\begingroup\$

As long as the PIC you are using has an "On-The-Go" port (for instance, all PIC32 chips with USB are On-The-Go) then what you are proposing is feasible.

The USB port provides a pin called "USBID". On USB Micro AB ports there are 5 pins. Pin 4 is the USBID pin (between D+ and GND) and is used by the chip to know if it's supposed to act as a host:

An OTG dual role device supports both USB host and device functionality. OTG dual role devices use a micro-AB receptacle. This allows a micro-A or a micro-B plug to be attached. Both the micro-A and micro-B plugs have an additional pin, the ID pin, to signify which plug type was con- nected. The plug type connected to the receptacle determines the default role of the host or device. An OTG device will perform the role of a host when a micro-A plug is detected. When a micro-B plug is detected, the role of a USB device is performed.

-- PIC32 Manual section 27

Making a fully OTG system though is quite an involved and specialized process, and unless you already know both host and device modes intimately I wouldn't be inclined to attempt it. Instead I'd separate out the two different roles into separate connections. Dedicating the USB to the USB Memory device simplifies the code massively. Routing the PC communications through a USB serial chip, such as an FT232R, PL2303, or MCP2200, for example, means you can then just use the simple UART device to do all PC communications. Time to market is reduced as you don't have to learn all about USB OTG, and it also gives you the advantage that you can have the USB MSD plugged in at the same time as the PC connection is active.

\$\endgroup\$
  • \$\begingroup\$ Hi Majenko and thanks for your answer. I have to connect a USB flash(thumb drive), for instance a 2GB one, to my device so i have to use type A jack on the device side which has 4 pins(2 for power and D- , D+). \$\endgroup\$ – hayat_bilgisi Sep 25 '14 at 7:12
  • \$\begingroup\$ Since, i plan to make connection to a PC, i will supply a cable which is type A plug to type A plug to the users of the device. I thought that the only point to detect which instrument is connected, is the power pin. If it is a PC, i should sense a 5V, but if it is a thumb drive i should supply 5V to this drive. So, if i can make this detection in a healty way, the mcu will decide to be a host or device. Is it possible, or can you think of any other possibilities? Again, thank you very much for your attention. \$\endgroup\$ – hayat_bilgisi Sep 25 '14 at 7:13
  • \$\begingroup\$ And i already thought of USB serial converter ic's like you mentioned but somehow i want to enter this new World of USB and learn something about this technology too. So, a real Project teachs new subjects better, i think. So i want to use USB if electronically possible. \$\endgroup\$ – hayat_bilgisi Sep 25 '14 at 7:14
  • 1
    \$\begingroup\$ To switch between HOST and DEVICE mode you have to use the USBID pin. You will need to provide a way for your MSD device to trigger the USBID pin, typically through an adapter cable. \$\endgroup\$ – Majenko Sep 25 '14 at 8:44
  • \$\begingroup\$ But MSD is 4pin. If i create an adapter cable such as usb type A-to-usb mini B inside my device, is it going to be like this one? Is this the sense(detect) method? Maybe i should connect VCC to sense in the linked Picture, right? \$\endgroup\$ – hayat_bilgisi Sep 25 '14 at 12:31
0
\$\begingroup\$

Try the PIC24FJNNNGB series (Not GA, where NNN is the program memory size in KB) they have an embedded USB host on the go inside the chip.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.