6
\$\begingroup\$

I'm designing a system and maybe (if I don't find better alternatives) I will need to use a PIC32 as a handler in between two USB devices and a host. My plan is to use the PIC32 to hide the devices, so the PIC has certain protocols downstream and another protocol upstream. I've been reading a lot about the USB specification and about the support of USB on Microchip PIC32 micro controller series. But still, I have one fundamental doubt: is it possible to connect two devices downstream of the PIC and to connect the PIC upstream to a host at the same time? In other words, is it possible for the PIC32 to act as a host and device at the same time?

I would really appreciate any hint or suggestion about this

Thanks in advance.

\$\endgroup\$
  • \$\begingroup\$ Are your upstream devices also USB (and you want to change the data they send and use), or are they using some other communication protocol? \$\endgroup\$ – Kevin Vermeer Sep 9 '11 at 15:02
  • \$\begingroup\$ @Kevin: exactly, the upstream devices are also USB. I want to communicate with them from the PIC, and then connect the PIC upstream with a PC, using another protocol. The PIC would be a handler in between the PC and the upstream devices. \$\endgroup\$ – Federico Sep 9 '11 at 15:24
  • \$\begingroup\$ The MAX3421E is a handy way to do embedded USB host, although it probably costs the same or more than a second PIC. circuitsathome.com/products-page/arduino-shields \$\endgroup\$ – joeforker Sep 9 '11 at 18:39
10
\$\begingroup\$

The USB can either be in device mode or in OTG mode. You cannot have OTG on the same USB bus as a host like a computer.

Multiple OTG devices can switch between host & device mode using "HNP" (Host negotiation protocol) but you can't do that with a pure host.

You would need two separate USB busses - one between the PC and the PIC, and one between the PIC and the devices. I don't think there is any PIC device that has 2 distinct USB interfaces.

I would suggest using a second device along side the PIC32 to act as a USB device to connect to the PC, and use the PIC32's USB in OTG mode to talk to the devices. This other device could be as simple as a FTDI chip to talk to the PIC32 through RS232, or something more powerful like another PIC (maybe a PIC18 with USB support) so you can talk through other protocols like I²C or SPI.

\$\endgroup\$
5
\$\begingroup\$

It seems you are talking about something similar to a USB hub. As Majenko says, (and as far as I know too) all the PIC32s only have one USB port, so this would not be possible with the PC involved.
You would need another USB device (e.g. FTDI, Cypress IC, another PIC) to connect the PIC32 to the PC, and then the PIC32 can act as host to the downstream devices.

As Kevin asks, do you have to talk to the devices with USB? If this is not a necessity then use SPI, I2C, UART or whatever and things become much simpler.
Telling us a bit more about the devices might bring forth some useful suggestions.

Depending on the processing power needed, you might want to look at Cypress and TI and FTDI (Viniculum?) as they do some USB controller ICs that have a uC built in, so may be a better choice than the PIC32.

\$\endgroup\$
  • \$\begingroup\$ in principle I have to, because I haven't found equivalent devices that use I2C for example...but of course, I would prefer to use I2C, UART or anything different from USB if I find that's a viable option. \$\endgroup\$ – Federico Sep 9 '11 at 16:21
  • \$\begingroup\$ @Frederico - updated answer regarding PIC32 alternative you might want to consider. \$\endgroup\$ – Oli Glaser Sep 9 '11 at 17:39
2
\$\begingroup\$

If what you are trying to do is connect 2 downstream devices to a PIC32, the answer is no... you would need a hub, and PICS don't have those drivers yet (not from Microchip) (unless you want to write the driver yourself, and share it with us, that'd be great ;-) )

If what you are trying to do is connect a PIC as a USB device, the answer is a simple yes. If what you are trying to do is connect a PIC as both a host and a device at the same time, the answer is a clear no. You would need a uC with 2 USB ports... no PICs yet.

Maybe your situation goes like this:

  • PIC-1 working as a device to get connected to the PC (able to "hide" your other devices)
  • PIC-2 working as a host connected to one of your devices
  • PIC-3 working as a host connected to your other device
  • PIC-1, PIC-2 and PIC-3 interconnected with i2c or other bus to share information among them
  • Finally, do PICs have the power to handle that situation, the answer is yes
\$\endgroup\$
  • 1
    \$\begingroup\$ Please DON"T use CAPITALIZATION when it's NOT REQUIRED. It makes your post MUCH HARDER TO READ. Also, CHECK THE FORMATTING in the PREVIEW area below your post, you'll note that a NEWLINE IS REQUIRED before any lists. ;-) \$\endgroup\$ – Kevin Vermeer Oct 25 '11 at 14:17
-1
\$\begingroup\$

This is what is known as a "how long is a piece of string" question. Th answer depends completely on how "hard" the device related tasks are. It is highly likely that you will be easily able to do what you want. But, read on ...

The only real issue should be "Has the PIC got enough resources?"

Resources here would include:

  • Processing power

  • Program memory

  • Data memory (RAM and flash)

  • Real time responsiveness (eg the ability to service interupts and carry out interupt driven tasks).

  • Special purpose peripherals (eg maybe hardware for USB and/or ethernet)

  • Other special features which make implementing a given device interface easier.

  • General I/O

  • Other ...

The PIC32 is reasonably capable. USB represents a reasonably heavy program load but it should be easy to determine how much resource it consumes. After that, how much resource in each category does each of the device interfaces require? and how much has the processor got left?

If your devices are anything like "normal" you will have no problem managing them and USB as well.

If your devices are especially demanding you will need to address each of the points above. For example, if you are attempting to manage a large flash card at 100 MB/s, or control a SATA drive without custom interface IC, or perform complex cryptography on data, or MPEG Video coding, or .... then you may well run out of horsepower.

\$\endgroup\$
  • \$\begingroup\$ ok, but is it possible for the PIC32 hardware to act as a USB host and function at the same time? I mean in a hardware/electrical sense...then I'll start studying if its performance is good enough. \$\endgroup\$ – Federico Sep 9 '11 at 14:51
  • \$\begingroup\$ @Federico - Exactly what you are trying to do is not clear. When you speak of other devices, do you intend then]m to be USB connected or connected in some other way? \$\endgroup\$ – Russell McMahon Sep 9 '11 at 14:56
  • \$\begingroup\$ a poor's man diagram to clarify the ideas: PC (host) <--- (funcion) PIC32 (host) <-- (funtion) devices. And both <-- (connections) working at the same time. Is that electrically possible with a PIC32? \$\endgroup\$ – Federico Sep 9 '11 at 15:04
  • \$\begingroup\$ @Federico - you need to answer the question that I and others have asked - what type of interface do you intend between each part.// USB forPC-PIC32?. USB for PIC32-function? \$\endgroup\$ – Russell McMahon Sep 9 '11 at 15:23
  • 2
    \$\begingroup\$ @Russell - I may be wrong but I don't think your interpreting the question quite right. I think Federico is looking for something closer to Majenko's answer. First, you can't have two host devices on the same USB bus which implies he needs a PIC32 device with two USB ports. Second, I doubt someone asking this level of question would want to bit-bang a USB interface on some GPIO pins...I think they would be looking for a PIC with two USB peripherals. Again, this is just my take on the question. \$\endgroup\$ – semaj Sep 9 '11 at 15:52

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.