18F2550 and USB - Page 1
Forum section: electronics / general

author: Dajgoro
author_rank: Frequent Contributor
timestamp: November 15, 2013, 11:16:57 pm
content: Hi.A couple a weeks ago a friend of mine came by and asked ma to program a 18F2550 for some project that he is working on. He gave me a hex file that he found on the web, and after a while we had it working just like it is supposed to work (using the pickit2, using the general propose programmer wont work for some reason). One week after, I found myself building another project, where I had issues with MPLABX, and that is when I started the other topic, but after reinstalling everything I eventually got it to compile some code. But when I would program the 18F2550 I would always get the unknown device info on Windows 7. Then I tried to find some hex files on the web of projects that actually work, and I programmed them into the 18f2550, but no change. Later I went to my friends house to get his rom file, but when he plugged his gizmo in the pc-usb it didn't work, and it never worked again. When I got home and plugged my gizmo i got nothing, not even the unknown device warning from windows. I tried downloading a bunch of various hex files from the web, but nothing happened.I checked the mcu, it is directly powered from the usb, 20MHz crystal that does oscillate, a resistor for mclr, and two wires for usb data, and that is it.But nothing works, I tried changing the chip itself, but nothing changes.I checked all of the connections with the multimeter, the usb cable, the usb port itself, but all seems to be fine!What can I try to do?I ran out of ideas!

author: Skimask
author_rank: Super Contributor
timestamp: November 16, 2013, 12:47:33 am
content: Quote from: Dajgoro on November 15, 2013, 11:16:57 pmAnd no idea what the config fuses are set at?QuoteWithout knowing anything else, circuit diagrams, or anything, 'cause the description of this thread sounds more like "my car won't start...it's red...what's wrong?", it sounds like MPLAB is probably setting the config fuses to some default value rather than what the circuit, more importantly, the PIC's USB module, actually needs.

author: trackman44
author_rank: Regular Contributor
timestamp: November 16, 2013, 01:00:35 am
content: It's stuck in LVP mode, here's a fix :-http://www.microchip.com/forums/m640643.aspxHope it helps.Will

author: Jon Chandler
author_rank: Frequent Contributor
timestamp: November 16, 2013, 01:05:13 am
content: One problem I've had with 18F2550s is that there must be a capacitor between Vusb and ground, 0.47 uF will work as I recall.This fact at least used to be a footnote in the data sheet and at least one Microchip demo board (MC9800 temperature sensor) doesn't have this cap and was un-recognized until I installed it.

author: Dajgoro
author_rank: Frequent Contributor
timestamp: November 17, 2013, 12:26:56 am
content: I've tried with this configuration:http://wiki.pinguino.cc/index.php/File:PIC18F2550_diagram.pngAnd also this:http://dangerousprototypes.com/2012/06/15/open-source-usb-demo-ported-to-the-pic18f2550-breakout-board/With a 12MHz crystal as well, but nothing!Its like I've been programming a brick tor the last two weeks.Btw, the rom and fuse settings are from the hex files of those sample projects.Is there a very simple usb demo that is known 100% that it works with a schematic, hex files and fuse settings?

author: Skimask
author_rank: Super Contributor
timestamp: November 17, 2013, 12:43:50 am
content: Read the PIC back and compare the ACTUAL config fuse settings in the .hex file.In the past, I've found that MPLAB and/or the programmer itself will override config fuses, even without you knowing it.So, write down what you think those config fuse settings should be, do a full read back of the PIC, and compare the two.

author: dannyf
author_rank: Super Contributor
timestamp: November 17, 2013, 01:41:37 am
content: QuoteNot sure if it is sufficiently simple for you but I do seem to recall that Microchip publishes a very well known USB device based on 18F2550, with schematic and hex files on its website.Simpler versions (and associated schematic) can be found on the web as well.

author: Dajgoro
author_rank: Frequent Contributor
timestamp: November 17, 2013, 04:57:43 am
content: I've downloaded an entire package of demo stuff from microchip, but that won't work either.

author: amyk
author_rank: Super Contributor
timestamp: November 17, 2013, 12:14:11 pm
content: Is itonlythe USB that's not working, or is it the whole MCU?Keep in mind that USB (although this is FS, not HS) is sensitive to length and noise on the data pair. Connections should be short and matched length, and the pair should be twisted together a far as possible until they enter the PCB.Try blinking an LED first...

author: dannyf
author_rank: Super Contributor
timestamp: November 17, 2013, 02:02:42 pm
content: QuoteThat's always the first step, usually skipped by people starting on mcus - they usually want to the fancy stuff right away.

author: Jon Chandler
author_rank: Frequent Contributor
timestamp: November 17, 2013, 04:47:14 pm
content: Blink an LEDandcheck that the period is correct. For example, blink it on for half a second, off for half a second and verify this time while watching a clock. This verifies the oscillator is set up correctly to yield the correct frequency.Commandments for Using PICsis a collection of common errors that lead to problems with PICs but it's pretty much applicable to any micro circuit.

author: David_AVD
author_rank: Super Contributor
timestamp: November 17, 2013, 08:37:07 pm
content: Quote from: Jon Chandler on November 17, 2013, 04:47:14 pmI've been programming micros for over 15 years and I still start with the blinking LED test with each new micro family/brand I use. It is a perfectly reasonable sanity check.

author: dannyf
author_rank: Super Contributor
timestamp: November 17, 2013, 09:03:39 pm
content: I see a pattern:seasoned programmer: blink the leds;newbie: work on usb or avr-based Ethernet traffic controller, or other equally challenging projects.

author: Dajgoro
author_rank: Frequent Contributor
timestamp: November 18, 2013, 07:44:45 am
content: Ok, I usually try that as well, but since I have to use MPLABX I wanted to avoid ti all together. Usually I use Proton IDE, and I never had such issues before with mcu-s. And I already checked the clock on the crystal, and it works just fine.

author: Skimask
author_rank: Super Contributor
timestamp: November 18, 2013, 01:29:01 pm
content: Quote from: Dajgoro on November 18, 2013, 07:44:45 amClock on the crystal and blinking LEDs, sure...that may work just fine and(or) dandy...but the USB module module runs off a different divider than does the rest of the PIC.How about posting the config fuse settings...or do we get to keep guessing at your particular configuration?

author: Dajgoro
author_rank: Frequent Contributor
timestamp: November 18, 2013, 07:13:44 pm
content: I wrote a blinky program in both Proton IDE and MPLAB X, and they both work fine, and I get pulses on portb, where it is supposed to "blink".For that programs I got the fuses set like this:CF3F 1F3F 8700 005E C00F E00F 400FFor the USB programs I tried so many different fuse configurations that I don't keep track of what it was supposed to be anymore...

author: Skimask
author_rank: Super Contributor
timestamp: November 18, 2013, 07:48:13 pm
content: And if you take those config fuse numbers, cross reference those with the PIC's datasheet, you should be able to figure out if you're crystal is getting divided correctly to give the USB module the right frequency to run off of...

author: DavidDLC
author_rank: Frequent Contributor
timestamp: November 18, 2013, 08:03:00 pm
content: I have project that works with USB and PIC18F2455.My configuration will see the device as a HID, so you also need to have the correct application on your computer because this is not a Virtual COM device and the PC application has to detect the USB device in a different way.You need to have the right oscillator settings for the 96 MHZ PLL in order to have USB working, the 96 MHz PLL needs a 4 MHz input. VUSB capacitor and some configurations to tell the system about your device, like VID and PID, if your device is powered or non-powered ( for this you need software settings and a resistor), and some other things I don't have straight on my mind.I'm at work right now I can check when I get home at 5:30 pm pacific time.David.

author: Dajgoro
author_rank: Frequent Contributor
timestamp: November 19, 2013, 02:36:11 am
content: The demo programs that I downloaded used a 20MHz and a 12MHz crystal oscillator, so I tried switching between the two. Not all demo programs use the same clock frequency, so the fuse bits are going to be different.That is why I asked for a example where I can just load the hex file, and input the fuse bits, eliminating any work from my side, since obviously I am doing something wrong.For now I don't care what type of hid it is, I just want that windows can recognize it as something, but my final goal is to get it working as a hid mouse.

author: trackman44
author_rank: Regular Contributor
timestamp: November 19, 2013, 04:46:04 am
content: Maybe it would be helpful if you posted your circuit diagram, links to the hid programs you downloaded, post some photos of your setup. I would recommend Pinguino :-http://www.pinguino.cc/It's a PIC18F2550 alternative to the Arduino Uno. It's worth a shot.Will

author: DavidDLC
author_rank: Frequent Contributor
timestamp: November 19, 2013, 05:52:14 am
content: I don't have a hex file, I have the entire project:This is the configuration for 20 MHz clock:#pragma config PLLDIV = 5 //20MHz / 5 = 4 MHz, input for the 96 MHz PLL#pragma config CPUDIV = OSC1_PLL2 //CPU Clock = 96 MHz/2 = 48 MHz#pragma config USBDIV = 2 //96MHz PLL/2 = 48 MHz for USB clock#pragma config FOSC = HSPLL_HS //Osc type: High Speed Crystal/Resonator with PLL enabledBut again, you may need to have voltage sense resistors to report to the host if you are a powered or non-powered device, if the hex file has this function enabled and you don't have the sense resistors connected, you can have the same problem you have.From the USB stack:static void InitializeSystem(void){// If the host PC sends a GetStatus (device) request, the firmware must respond// and let the host know if the USB peripheral device is currently bus powered// or self powered.If the peripheral device is capable of being both// self and bus powered, it should not return a hard coded value for this request.// Instead, firmware should check if it is currently self or bus powered, and// respond accordingly. If using this feature, make sure "USE_SELF_POWER_SENSE_IO"// has been defined in HardwareProfile.h, and that an appropriate I/O pin has been mapped// to it in HardwareProfile.h.#if defined(USE_SELF_POWER_SENSE_IO)tris_self_power = INPUT_PIN; // See HardwareProfile.h#endif}//end InitializeSystemIn one of my projects I didn't put the sense resistor, and the circuit was not recognized, I was having the same problem as you.David.

author: sata
author_rank: Newbie
timestamp: December 21, 2013, 01:13:07 pm
content: What do you mean config fuse numbers? Are you mentioning the Configuration bits?

author: Skimask
author_rank: Super Contributor
timestamp: December 21, 2013, 06:14:10 pm
content: Quote from: sata on December 21, 2013, 01:13:07 pmYes, and the number that those bits represent...

author: Dajgoro
author_rank: Frequent Contributor
timestamp: February 16, 2014, 11:33:57 pm
content: After a longer brake from this mess, I finally obtained a development board for the 18F2550, it is the RKPK28.Guess what!None of the examples work, and the site of that dev board is dead!The pickit2 programs the board, but nothing happens, widows don't give any signs of activity, not even an unknown device. Nothing, as if I plugged the usb cable in a brick.I am out of ideas here, what else can I try to getANYusb example to work.

author: daveshah
author_rank: Unknown
timestamp: February 17, 2014, 11:06:56 am
content: Quote from: Dajgoro on February 16, 2014, 11:33:57 pmIt looks like the site might be back up -www.rkeducation.co.uk/RKPK28.php- and a schematic is available athttp://rkeducation.co.uk/images/Schematics/rkpk28schematicsheet1.jpg.As for the USB - have you connected D+/D- to RC5/RC4?

author: JTR
author_rank: Regular Contributor
timestamp: February 17, 2014, 12:45:59 pm
content: Quote from: daveshah on February 17, 2014, 11:06:56 amWhat an awful circuit. 3.3V regulator taps off the 12V output and not the 5V output. No diode across the 7805 to protect against USB power > input terminal. No cap on Vusb, wrong crystal speed (for USB) on circuit diagram.OK, I'm going to stop now.

author: Skimask
author_rank: Super Contributor
timestamp: February 17, 2014, 12:59:39 pm
content: Quote from: Dajgoro on February 16, 2014, 11:33:57 pmhttp://www.picbasic.co.uk/forum/showthread.php?t=5418

author: Dajgoro
author_rank: Frequent Contributor
timestamp: February 17, 2014, 04:29:56 pm
content: Quote from: daveshah on February 17, 2014, 11:06:56 amI did that now, when the website finally decided to come up again.I got the thing without any instructions whatsoever.Ok, I now soldered the two wires, and progress! Now I get an unrecognized usb device for every example!Also, it came with a 16MHz ceramic filter, and not with a 10MHz crystal.Quote from: JTR on February 17, 2014, 12:45:59 pmIndeed, if I want to turn the thing off, I have to unplug the usb.No Vusb? So I have to add even that?Is this a dev board or a figure it out yourself board?Anyway, what is the right frequency for most of the examples? 20MHz, 4MHz?Edit: That USB demo doesn't work on win 7.Edit2: I fixed the thing, and tried this demo (20MHz osc, and added vusb cap):http://projectproto.blogspot.com/2009/11/pic18f2550-usb-hid-mouse.htmlOf course, I just get an unknown device...

author: David_AVD
author_rank: Super Contributor
timestamp: February 17, 2014, 08:42:32 pm
content: An "unknown device" error can be the D+ and D- wires swapped. or one of them shorted to 0V. Might not be the case here, but worth checking.

author: Dajgoro
author_rank: Frequent Contributor
timestamp: February 17, 2014, 09:23:05 pm
content: Quote from: David_AVD on February 17, 2014, 08:42:32 pmI checked once again, it is ok.

author: diyaudio
author_rank: Frequent Contributor
timestamp: February 17, 2014, 09:57:02 pm
content: Quote from: DajgoroHi,Some time ago, about two years ago I successfully got a PIC-4550 to run the USB microchip stack see attachment (I developed a novel 4 channel multimeter (client written in C# .NET) to measure AAA batteries), I must say the USB stack was challenging to get working and it still is cause so much can go wrong and its very bloated (to run all the families using one build)Here are some tips (things I did as to get my project working)1) Use the demo supplied example code, unmodified, try out the CDC basic demo its a simple USB to SERIAL demo and it works ! (in fact I used that as a skeleton for my project as I was unable to move, USB library dependences to a custom directory, I used the demo, with all the correct includes )2) Have you installed the microchip "mchpcdc.inf" driver ?? You must install this driver else no USB communication is established. it comes with the SDK read the demo setup documents.3) Breadboard a test fixture, as the members already probably described check your connections, I had issues with D-, D+ not making contact with the pins of the PIC resulting in communication issues, so check that out.4) If you use the " CDC basic demo" you don't need to compile, the SDK comes supplied with the HEX file (pre-built), I would recommend you learn to recompile "tear it apart" and strip it down for one family, like a PIC 4550, 2550 so its bit bit cleaner. (I did this cause at the time I was learning that processor)Consider this, it took two weeks to get this working and it was fun and $#e%$# at the same time.Good luck.

author: Anks
author_rank: Frequent Contributor
timestamp: February 17, 2014, 10:12:35 pm
content: I got the microchip and the DP open source stack to work recently and even ported part of the code to another pic. I lost a hard drive and due to the pain I wont be doing it again.Im just going to use a different micro for usb in future.

author: diyaudio
author_rank: Frequent Contributor
timestamp: February 17, 2014, 10:19:46 pm
content: Quote from: Anks on February 17, 2014, 10:12:35 pmYeah I saw that one. never used the DP stack yet, The microchip forum is filled with people complaining about the usb bloat.I prefer now using a FTDI for serial stuff it just works. I have never used the USB protocol.

author: Dajgoro
author_rank: Frequent Contributor
timestamp: February 18, 2014, 12:16:04 am
content: Aaaaaaaaaannnnnnnnnnddddddddd, nothing!I installed the sdk and demo pack a long time ago when I first tried poking with the thing.I tried the CDC demo, once again, and nothing.MPLAB X changed his mind, and now it won't recognize the libraries of the examples once again.I managed to fix that a while ago, but Mplabx changed his mind once again.About mchpcdc.inf, I've tried to install it once again, but how do I install that, installing via windows just gives me a big error.

author: daveshah
author_rank: Unknown
timestamp: February 18, 2014, 09:19:18 am
content: Quote from: Dajgoro on February 17, 2014, 04:29:56 pmI seem to remember having a lot of trouble with a PIC-based USB device that used a ceramic resonator rather than a crystal not being recognised (not sure whether the problem was accuracy or stability), so if you have a 16MHz crystal available you could try replacing it.I think I got the aforementioned device working in the end on an older laptop running Windows XP, so that might be another option.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: February 18, 2014, 10:26:05 am
content: I would recommend this simple toolhttp://www.uwe-sieber.de/usbtreeview_e.htmlto separate bus level errors from OS/inf/driver problems - if you don't see your correct vid/pid/speed there, then no need to waste time on PC side, your device is unable to send device descriptor to be recognized

author: Dajgoro
author_rank: Frequent Contributor
timestamp: February 18, 2014, 04:00:12 pm
content: Quote from: abyrvalg on February 18, 2014, 10:26:05 amI ran the program, and I got this:Code:=========================== USB Port4 ===========================Connection Status : Device failed enumerationPort Chain : 6-4======================== USB Device ========================+++++++++++++++++ Device Information ++++++++++++++++++Device Description : Unknown DeviceDevice ID : USB\VID_0000&PID_0000\5&4A9E079&0&4Driver KeyName : {36fc9e60-c465-11cf-8056-444553540000}\0060 (GUID_DEVCLASS_USB)Legacy BusType : PNPBusClass : USBService :Enumerator : USBLocation Info : Port_#0004.Hub_#0006Manufacturer Info : (Standard USB Host Controller)Capabilities : Removable, RawDeviceOKAddress : 4Problem Code : 43 (CM_PROB_FAILED_POST_START)Power State : D3 (supported: D0, D2, D3, wake from D0, wake from D2)---------------- Connection Information ---------------Connection Index : 0x04Connection Status : 0x02 (DeviceFailedEnumeration)Current Config Value : 0x00Device Address : 0x00Is Hub : 0x00 (no)Number Of Open Pipes : 0x00 (0)Device Bus Speed : 0x00 (Low-Speed)------------------ Device Descriptor ------------------bLength : 0x00 (0 bytes)Edit: On the other hand, I am using a Pickit2 for programming the thing, and in there is the 18F2550, and the pickit works fine.Edit2: As I already wrote, I replaced the filter with a 20MHz crystal to suit the demo.I have a stack of crystals, so I can set it to any frequency, depending on the requirements.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: February 18, 2014, 06:23:46 pm
content: Enumeration failed, no communication at all (vid/pid/device desc size are all 0), so the problem is on device side. Your code is running (pullup gets activated, otherwise you'll not see any device attach at all), but some setup is wrong (clocking, D+/D- polarity - try swapping them just be sure, I've spent a day tweaking my first USB device being 100% sure that it has correct polarity, then swapped D+/D- desperately and it started to work)

author: Dajgoro
author_rank: Frequent Contributor
timestamp: February 18, 2014, 07:06:05 pm
content: Quote from: abyrvalg on February 18, 2014, 06:23:46 pm...Yup, the D+ D- marks on the pcb are reversed.It works now.At least the basic demo, still a long way to go to get a compiled code to work...

author: David_AVD
author_rank: Super Contributor
timestamp: February 18, 2014, 09:55:51 pm
content: See, what did I say? There's a reason I never assume anything. Hopefully lesson leaned.