PIC as a USB host - Page 1
Forum section: electronics / general

author: and101
author_rank: Contributor
timestamp: March 13, 2014, 10:35:53 am
content: 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?

author: dannyf
author_rank: Super Contributor
timestamp: March 13, 2014, 11:32:35 am
content: Yes.1) Microsoft has a usb stack;2) there are "software usb" implementation on the avr that you could port to your pic.

author: ElektroQuark
author_rank: Unknown
timestamp: March 13, 2014, 11:57:13 am
content: Quote from: dannyf on March 13, 2014, 11:32:35 amsoft chip.

author: and101
author_rank: Contributor
timestamp: March 13, 2014, 12:02:11 pm
content: Thanks for that, I will start digging through the Microchip usb stack and try and make sense of it.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: March 13, 2014, 12:38:29 pm
content: 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.

author: JTR
author_rank: Regular Contributor
timestamp: March 13, 2014, 12:58:50 pm
content: Quote from: mikeselectricstuff on March 13, 2014, 12:38:29 pmThere are no PIC18 devices that support USB HOST mode, none...

author: NiHaoMike
author_rank: Super Contributor
timestamp: March 13, 2014, 02:04:17 pm
content: 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.

author: and101
author_rank: Contributor
timestamp: March 13, 2014, 02:10:28 pm
content: 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?

author: nctnico
author_rank: Super Contributor
timestamp: March 13, 2014, 02:38:50 pm
content: 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.

author: and101
author_rank: Contributor
timestamp: March 13, 2014, 03:26:51 pm
content: So use something likethisto switch between the data pins on each usb port and then poll the port to see if a device is connected?

author: mazurov
author_rank: Frequent Contributor
timestamp: March 13, 2014, 04:08:48 pm
content: 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.

author: photon
author_rank: Frequent Contributor
timestamp: August 02, 2014, 11:09:49 pm
content: Quote from: and101 on March 13, 2014, 03:26:51 pmI 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.

author: photon
author_rank: Frequent Contributor
timestamp: August 02, 2014, 11:24:30 pm
content: Thishttp://www.ti.com/product/TUSB2046B/samplebuyis chip you may consider.