Author Topic: PIC as a USB host  (Read 9895 times)

0 Members and 1 Guest are viewing this topic.

Offline and101Topic starter

  • Contributor
  • Posts: 45
  • Country: gb
PIC as a USB host
« on: March 13, 2014, 10:35:53 am »
I am trying to design an intelligent USB charger which can keep track of the devices that are plugged into it so for example it could tell me that an iPad was charging for 6 hours and a phone was charging for 4 hours.  I need some way of reading the vendor and product id from a device when it is plugged into the charger and relay that back to a central hub over an RS485 bus.

Does anyone know if it is possible to use a PIC microcontroller as a USB host device and if one could be used to read the vendor and product ids from any connected usb devices?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC as a USB host
« Reply #1 on: March 13, 2014, 11:32:35 am »
Yes.

1) Microsoft has a usb stack;
2) there are "software usb" implementation on the avr that you could port to your pic.
================================
https://dannyelectronics.wordpress.com/
 

Offline ElektroQuark

  • Supporter
  • ****
  • Posts: 1244
  • Country: es
    • ElektroQuark
Re: PIC as a USB host
« Reply #2 on: March 13, 2014, 11:57:13 am »
1) Microsoft has a usb stack;

soft chip.

Offline and101Topic starter

  • Contributor
  • Posts: 45
  • Country: gb
Re: PIC as a USB host
« Reply #3 on: March 13, 2014, 12:02:11 pm »
Thanks for that, I will start digging through the Microchip usb stack and try and make sense of it.
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13745
  • Country: gb
    • Mike's Electric Stuff
Re: PIC as a USB host
« Reply #4 on: March 13, 2014, 12:38:29 pm »
Several PIC24 devices support USB host/OTG, e.g. pic24fj64gb002 - I think also one or two PIC18s but ISTR it's a bit of a mess on the Pic18 - seem to be a lot of fudgy build options in the USB stack for PIC18s.
Microchip's USB stack seems to be reasonably documented but you may have to do some work to get what you need - all source is provided.
   
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline JTR

  • Regular Contributor
  • *
  • Posts: 107
  • Country: au
Re: PIC as a USB host
« Reply #5 on: March 13, 2014, 12:58:50 pm »
I think also one or two PIC18s

There are no PIC18 devices that support USB HOST mode, none...
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9013
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: PIC as a USB host
« Reply #6 on: March 13, 2014, 02:04:17 pm »
PIC24 is available with USB host, but it doesn't support USB hubs. If you need more than a few ports, it would probably make more sense to use a controller that does support USB hubs, like many of the ARM chips with USB host. You'll also need to support USB CDP for newer devices, which could be as simple as a few comparators and resistors attached to a few GPIOs, but I haven't looked too closely at that.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline and101Topic starter

  • Contributor
  • Posts: 45
  • Country: gb
Re: PIC as a USB host
« Reply #7 on: March 13, 2014, 02:10:28 pm »
I have downloaded Microchips source libraries and it looks like there is an example library for making a charger usb host so hopefully I can use that as a base and build everything else around it.  The pic24fj64gb002 looks like it should be suitable, I have ordered a few samples from Microchip so once they arrive I can get to work designing the firmware.  That PIC also includes a real-time clock which will be handy for keeping track of when devices are attached and removed.

Now I just need to get my head around how the USB stack works as I haven't done much with USB in the past. :-\

Will I need a hub if I want to connect two devices to the same usb port?
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: PIC as a USB host
« Reply #8 on: March 13, 2014, 02:38:50 pm »
Yes but your software needs to support the HUB mode as well...
A way around would be to use an analog mux to select between the ports. That way you poll the devices.
« Last Edit: March 13, 2014, 02:41:04 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline and101Topic starter

  • Contributor
  • Posts: 45
  • Country: gb
Re: PIC as a USB host
« Reply #9 on: March 13, 2014, 03:26:51 pm »
So use something like this to switch between the data pins on each usb port and then poll the port to see if a device is connected?
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 524
  • Country: us
Re: PIC as a USB host
« Reply #10 on: March 13, 2014, 04:08:48 pm »
USB hub only needs to be "supported" when you have a low speed device connected to a full speed hub. If everything is the same speed hub is transparent. PIC24 does support this mixed speed mode but the feature is presumably buggy (PRE token generation) . Freescale Kinetis series ARM chips have USB SIE which looks identical to PIC24. They also have a stack for it; while studying the source code I noticed a comment indicating that certain registers must  be loaded in a certain order otherwise PRE won't be generated properly. I suspect the same is true for Microchip  implementation, they just don't know that.
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline photon

  • Regular Contributor
  • *
  • Posts: 234
  • Country: us
Re: PIC as a USB host
« Reply #11 on: August 02, 2014, 11:09:49 pm »
So use something like this to switch between the data pins on each usb port and then poll the port to see if a device is connected?
I think the MAX4906EF is only useful to switch USB devices after the link is closed. For example, using it you could charge a USB device on port A and then when that is fully charged switch to charging the device on port B. However, for a solution that charges more than 1 device at the same time you need to connect the multiple devices to a hub.

The reason, I think, you cannot use the MAX4806EF as a dynamic switch is because the host and device are constantly in communication and if, say, the device goes idle, the host may put the device in standby.
 

Offline photon

  • Regular Contributor
  • *
  • Posts: 234
  • Country: us
Re: PIC as a USB host
« Reply #12 on: August 02, 2014, 11:24:30 pm »
This http://www.ti.com/product/TUSB2046B/samplebuy is chip you may consider.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf