Need a push in the right direction for interfacing with USB Device - Page 1
Forum section: electronics / projects

author: LittleRain
author_rank: Contributor
timestamp: November 02, 2018, 05:25:32 am
content: What I'm trying to do is read inputs from a USB Game pad(Xbox360), with a micro controller.I need help figuring out how USB data is communicated.I'll need to be able to initialize the device, and then of course read the data it sends.I've hooked the game pad up to a logic analyzer, and captured the moments of plugging the device in.I was hoping someone could help shed some light on whats happening.Here is the data I captured.upload picutreIn the first row, it is just plugged into a power source, it doesn't get initialized so it doesn't start sending packets.The second row its plugged into a PC, as you can see it starts sending packets.The third row, is the same capture as the second row, but I've added some measurements for a"bookmark". (I just realized there is minor differences between row 2 and 3, but that's only because of zoom level).Is someone able to explain what is being sent, and how it is being sent (like which bits do what), between the"bookmarks"in the image?Or even if I could just get a pointer to where I could begin to understand all of it. (I do understand the basics, kind of. Like how this would be an interrupt transfer type, and how this would be high speed because D+ is pulled high).I really just need to get a good starting point.Any help is greatly appreciated, thanks.

author: ataradov
author_rank: Super Contributor
timestamp: November 02, 2018, 05:34:09 am
content: Analyzing USB using logic analyzer is going to be hard/impossible.You either need a hardware analyzer (expensive), software analyzer (cheap/free, but possibly glitchy), or just plug it into the OS that can provide good debug info (Linux) and read the device descriptors. It may be a simple USB HID device.If you have never worked with USB, explaining it in a forum post is pretty much impossible. USB 2.0 specification is 650 pages long. You don't need most of it, but you still need a good chunk.Also what MCU are you using? You don't think about implementing this in software by bit-banging the USB protocol, do you?

author: rs20
author_rank: Super Contributor
timestamp: November 02, 2018, 05:41:38 am
content: I'd strongly recommend starting by getting a development board that has a microcontroller on it that speaks USB directly (i.e., none of this Arduino nonsense) (a specific example might include the STM32F072B-DISCO board); andbuilding a game pad devicefirst. It obviously doesn't have to be fully featured, but by building a super basic "game pad" that just has a couple of buttons, exposing it as a USB HID device, and getting that working on a PC, you'll hopefully learn a whole lot of stuff that will be invaluable to deciphering whatever it is that an Xbox360 controller is doing.I do know for a fact that Xbox360 controllers are supported on Linux, but I also vaguely remember that the Xbox360 Elite controllers were only supported quite recently, which makes it sound like they are maybenotstandard USB HID controllers. But on the plus side, the source code of the Linux drivers is out there, so there's some prior art you can build off of.EDIT: One other issue, IIRC, is that many USB-capable microcontrollers are USB-deviceonly, and can't act as a USB-host. Another thing to watch out for when selecting a development board/MCU for your actual project.And as ataradov pointed out; do not try to bit-bang USB.

author: ataradov
author_rank: Super Contributor
timestamp: November 02, 2018, 05:42:44 am
content: Yes, that too. I strongly suspect that those controllers are well documented by now.

author: Geoff_S
author_rank: Regular Contributor
timestamp: November 02, 2018, 07:54:29 am
content: Jan Axlson has a great website on USB (and a book also). Suggest you start there. And then get a USB analyser since a logic analyser is too low-level to be of much help for what you're trying to do.http://janaxelson.com/usb.htm

author: MosherIV
author_rank: Super Contributor
timestamp: November 02, 2018, 07:57:32 am
content: As Geoff_s said.(Your search foo is weak)Also tryhttps://en.m.wikipedia.org/wiki/USBhttps://www.beyondlogic.org/usbnutshell/usb1.shtml

author: krisRaba
author_rank: Regular Contributor
timestamp: November 03, 2018, 07:06:26 pm
content: If you connect it to PC and it communicates - check on PC what type of USB device it is. This will be your first direction sign and you will know what to search for.If you use Windows go to Device manager and check in two categories - USB HID devices and Sound, video and game controllers.You can also try this tool -https://www.thesycon.de/eng/usb_descriptordumper.shtmlYou plug in your device, select it on list and then unplug and plug in again. It should list everything that is read from descriptors. Then you can try to understand (with documentation) what all these values mean. Search for "USB descriptor" to finde some pages that explain it in easy to understand way.Descriptor info gives you knowledge of exchanged data frame formats etc.

author: LittleRain
author_rank: Contributor
timestamp: November 04, 2018, 01:15:07 am
content: ataradovMan, I had no idea they had analyzers specifically for USB, guess I'll put it on my wish list.I'm going to give this free one a shot. -https://freeusbanalyzer.com/Have you (or anyone) ever used this before?I do have another PC running an older version of Ubuntu, although its very old and slow and the hard drive is about to fail, but I'll try that if I run into any walls.I was going to use the Atmega32u4, but to be honest I'm still not totally sure how I was going to do it.I guess I'll start reading those docs, I just found a 97 page one on HID so hopefully I'll be able to figure it out.Thanks.rs20I wasn't going to use an Arduino, per say, but I was going to use the Atmega32u4.I have a bunch of them, and the 32u4 does already have USB functionality.That board looks pretty nifty, especially for the price, I'll order one and give it a go.Personally I have never used an ARM micro controller, but its been on my to do list. The stm32f072c8t6 has been sitting in my cart for a couple weeks now, but I'll get that one instead.I have actually made a few controllers before, one was a USB device, andthe other was for the Original Nintendo Entertainment System.The one for the Nintendo literally just used a shift register.And I will admit that I had cheated with my USB game pad, of course by using the Arduino HID library, so I really didn't learn anything at all.Currently I'm just trying to read the data from controllers, but I did have another controller planned, so that might be the best way to learn.That's a great idea, I never thought to look at the linux drivers. I was looking at the Arduino HID library the other day, but it wasn't too helpful in the sense that I need to know what the X360 controller is sending.Ahh that's really shitty, cause the Atmega32u4 does not act as a host.. Looks like the STM32F072 is going to be my best bet.Thanks.Geoff_SFunny, I did briefly look at his website/book the other day but didn't really want to dish out $50 at the moment. But luckily I just found a 4th edition for $10 CAD on amazon so its on its way.Thanks.MosherIVwww.usb.orgis betterThanks.krisRabaCool, I'll check that out.It could be useful paired with a USB Protocol Analyzer. I'm thinking that maybe its possible that I will see data sent on the lines, matching values in the descriptor. But I'm not totally sure.Thanks.Thanks a lot everyone, looks like I have quite the amount of work ahead of me, its definitely a lot more complicated than I had hoped.

author: ataradov
author_rank: Super Contributor
timestamp: November 04, 2018, 01:18:53 am
content: Quote from: LittleRain on November 04, 2018, 01:15:07 amI'm working on one myself at the momentQuote from: LittleRain on November 04, 2018, 01:15:07 amThere has been a number of them. I found them very inconsistent and touchy. It is understandable, they do a very low level stuff. So there is really no telling if one will work on your system. Just give it a go and see if it works.Quote from: LittleRain on November 04, 2018, 01:15:07 amThis chip does not have USB Host controller, so you can't use it for this project.Although as it was pointed out, you don't need any of this, since there is a good chance that you will find documentation for the protocol. If it is HID, then it is relatively easy to interface it.

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 04, 2018, 01:31:28 am
content: You need to implement an USB host.Implementing it from scratch and from analyzing USB signals is crazy and close to useless. The USB protocol is well documented, the game pads are HID devices and well documented as well. But implementing that at a low level would be completely crazy IMO.Some MCUs can act as simple USB hosts (those having USB OTG ports for instance). FTDI also has USB host ICs (see the Vinculum series for instance). I would look at either solution.

author: rs20
author_rank: Super Contributor
timestamp: November 04, 2018, 02:04:59 am
content: Quote from: LittleRain on November 04, 2018, 01:15:07 amJust to clarify, you could be forgiven for thinking that the STM32F072 supports being a USB host because in a single post I a) recommended its dev board and b) said it was important that the MCU supports being a host. However, please double-check that, I'm pretty sure it actuallydoesn'tsupport it. Sorry for the poorly thought-out recommendation.

author: voltsandjolts
author_rank: Unknown
timestamp: November 04, 2018, 04:19:32 pm
content: If you can switch to PS3/4 game pad, someone has done the hard work for you:http://www.hobbytronics.co.uk/usb-host-board-v2

author: LittleRain
author_rank: Contributor
timestamp: November 11, 2018, 11:44:54 pm
content: Quote from: ataradov on November 04, 2018, 01:18:53 amAre you going to opensource it?Still haven't found the time to try it yet, but I hope I wont need to dish out $500.Yeah after he mentioned it I realized it didn't have host capability.Quote from: SiliconWizard on November 04, 2018, 01:31:28 amI'm going to go the host route, and if I remember correctly, the STM32F072 which was recommended does have it. I'll definitely check that out though.Quote from: rs20 on November 04, 2018, 02:04:59 amI remember checking it out and finding out that it does have host capabilities. It could have been another similar one but I'm pretty sure.Quote from: voltsandjolts on November 04, 2018, 04:19:32 pmI was actually going to do both haha. Was going to start with the Xbox 360 and then do PS3.The plan was to make a device similar to the "Titan One" adapter.

author: ataradov
author_rank: Super Contributor
timestamp: November 11, 2018, 11:47:34 pm
content: Quote from: LittleRain on November 11, 2018, 11:44:54 pmYes, but it will take time, since it is more of a "do it right" project rather than a quick hack. I'm trying a lot new stuff I need to learn.