electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

PIC18F4550 and USB - help needed


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> PIC18F4550 and USB - help needed
Author Message
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post24 May 2009 9:22   

pic18f tutorial


Hello Folks,
I finally laid my hands on a couple of 18Fs that I wanted to try out with USB. I've done all the typical stuff, got the datasheet, went through the basics, still getting used to the slightly different memory organization (compared to 16Fs), and more freedom Smile.

Anyway, I've searched all around for a USB tutorial specific to that series of MCUs, and I haven't found almost anything. I already went through the "USB" chapter of the datasheet, and I understand that part, but it really doesn't say much on how to actually "communicate". For example, when working with PWM, you set all the registers the way you want them, and turn on the module by setting a bit - and it does it's thing the way you set it. This doesn't seem to be the case with USB, it seems - because you set some things, you enable the module...and what then? The Host and the device are supposed to have a little chat about who is who and what is what, and then what happens? How do I make the MCU actually send something out?

P.S. I'm quite good with C (done many programs for Windows and Linux using C) but I've never really liked C for MCUs, I don't know why. Instead, I've either done it in ASM or Basic (had a neat little simulator specifically designed for these PICs and it had a nifty little Basic compiler that had several important things built in as procedures/macros). So, when I go through the example C code from Microchip website, I really don't get anything...mainly because I'd have to look at 16 different sources and headers just to understand what is being done to "initialize" the USB module.


Help is greatly appreciated Smile




EDIT: I've changed the topic title to avoid confusion.


Last edited by jumper2high on 24 May 2009 11:46; edited 1 time in total
Back to top
FvM



Joined: 22 Jan 2008
Posts: 5154
Helped: 766
Location: Bochum, Germany


Post24 May 2009 9:55   

pic usb tutorial


I can hardly imagine, that you'll learn USB basics from a PIC datasheet or Microsoft driver literature. There are good tutorials and books, e.g. Jan Axelsons USB complete, see http://www.lvr.com/usb.htm for this and other references. Also the official USB 2.0 standard from usb.org is basically a better literature.

For a more practical start, most PIC toolchains, e.g. Microchip, CCS come with ready to use USB example applications. You don't need to start your application from the scratch, although this can be instructive as well.

Personally, I don't see a particular eternal struggle in the USB field. You should know, what you want to do, check if it's basically feasible (you can't e.g. interface an USB memory stick with 18F4550) and start writing your application. You shouldn't let you deter from edaboard posts, that report failure of their USB applications. There are also many examples, that even failed to blink a LED.
Back to top
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post24 May 2009 11:45   

pic18f4550 tutorial


Thanks for the reply. Maybe the topic title wasn't quite appropriate (I'm not a native English speaker), but I really searched for a while now (three weeks while waiting for the MCUs to arrive) and I wasn't able to find a single tutorial for PIC18F-s regarding USB.

I got a "USB Complete" book by Jan Axelson, and I went through the first four chapters. It did give me some of the information I was looking for, but I'm still stuck with the actual firmware bit. Since I'm "learning" this for a reason (freetime project in mind) I will have to start writing my own firmware sooner or later, so I guess it's better to start from scratch right away, rather than using something pre-made.

As I said earlier, I do have a basic understanding how USB works, but I don't know how to do that with the PIC. For example, I don't know how would I make the MCU respond to the Host's interrogation, or how to send the desired data to the host.
Back to top
FvM



Joined: 22 Jan 2008
Posts: 5154
Helped: 766
Location: Bochum, Germany


Post24 May 2009 13:23   

short explanation on what a usb is all about


I just can say, that the standard USB example projects (e.g. CDC or HID) supplied with Microchip or CCS tools are basically working.

To design it on your own, you have to understand of course the different layers of USB communication. It's not bad to start at the physical layer respectively bit level, continue with request and response packets, in and out transactions, enumeration, data transfer and device class specific stuff.
Back to top
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post24 May 2009 13:53   

pic18f2550 usb tutorial


I'll take a closer look at those when I have a chance.

I think the biggest issue I'm facing right now is actually caused by the "example code" versatility. Most of them are written so that they can be burned on different devices, with different circuits, or with different conditions - that makes them large, and for me at least, harder to understand.

That's why I was looking for something that was specific to the PIC18F series, or even better for the PIC18F4550 itself.


For the sake of discussion, let's say the device gets properly recognized and identified, and I want to send a few bytes from the device to the PC. Also, assuming the PC has the correct drivers and software to catch those bytes, could someone explain the process (in short, without spending too much time on details) of how to prepare the data (where to put them in the memory) and making the device actually transmit them outwards?
Back to top
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post25 May 2009 17:41   

codes for usb enumeration of pic18f4550


Sorry for double posting, but I got a few things to add:

I've spent all day yesterday and most of the day today (almost 7PM at the moment) trying to make anything work with USB. I've started with the stuff that I got from Microchip. After a lot of time I spent actually setting up all the paths, and finally managing to compile the HID - Mouse Demo, I whacked it onto the PIC, and nothing happened. The PIC is connected in a circuit near-identical to the one found on the Microchip Development board schematic. I then tried the Bootloader that I found in the same package. Nothing happened there either.

I then tried examples from the CCS library (Drivers) but I wasn't able to get anything working since it's all stuffed in one folder with no explanation on what is what.

Afterwards, I tried a few examples that came with MikroC, with similar results - but this time, Windows actually acknowledged a device being connected, but failed to recognize it. Using the Microchip's HID USB drivers (as suggested by the readme) didn't help either, because the device was just dubbed "Unknown Device".

I then found, by accident, a British (UK) website that had a USB Demo written for PIC18F4550 (the MCU I'm using). I downloaded it, I connected up the circuit exactly as described on the article, compiled the source using MPLAB, but the configuration bits weren't "set" according to the programming software (WinPIC) so I set them manually in there. Once I programmed the device and plugged it in, nothing happened once again.

After the previous failed attempt, now slightly losing hope, I tried the Bootloader from the same british website. I downloaded the pre-compiled HEX file, and followed the instructions step by step, connecting up the circuit as described (the guide actually said to connect it up the same way it was in the previous demo (previous paragraph), and then said "Reset the device while holding SW2"...the only problem is that the circuit that was given had no switches in it, at all.

(I apologize for the really long post)

After several other failed attempts with various sources (I won't waste your time describing them all to you) I figured out some other "basics" that seem to be used for most of them, so at least SOME good came out of this, but I still haven't managed to get anything working.


So, a revised question: Does anyone know a USB/PIC18F4550 based tutorial/demo that actually works out of the box, or contains instructions on how to make it work properly? really tried hard to find one, but only ended up with a slightly elevated blood pressure. Neutral
Back to top
Google
AdSense
Google Adsense




Post25 May 2009 17:41   

Ads




Back to top
FvM



Joined: 22 Jan 2008
Posts: 5154
Helped: 766
Location: Bochum, Germany


Post25 May 2009 18:04   

usb pic18f tutorial


For the requested short explanation:

USB communication is basically organized on in endpoints which are independent channels. They are defined in the device descriptor data structure, that is read during device enumeration by the host, in other words, when you plug in the device.

Sending to the host involves writing the data to a buffer and tell the USB controller, that they are ready for transmission.

Regarding CCS examples, I just can say that ex_usb_serial work for me on a 18F4550, and also for other CCS users, as far as I'm aware of.
Back to top
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post25 May 2009 18:23   

use usb communication with pic18f4550


FvM, once again, thank you very much for the answer!


FvM wrote:
...tell the USB controller, that they are ready for transmission...


Yes, but how? Smile That's what I'm asking. How do you tell the Controller they are ready?
Back to top
kejian2000



Joined: 15 Oct 2008
Posts: 7


Post26 May 2009 17:48   

libusb pic18f


hi,jumper2high
do you familiar with USB Protocol ?
if not,learn it ,or you will not get 18f4550 work...

maybe this file will be useful,build it with MPLAB C30



Sorry, but you need login in to view this attachment

Back to top
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post26 May 2009 19:59   

pic18f cdc usb application note


Keijan,
I have read a few books about the USB protocol, so I think I have sufficient base-knowledge to get the examples to work.

Also, I'm using PIC18F devices.
Back to top
Kabanga



Joined: 04 Oct 2007
Posts: 70
Helped: 5


Post28 May 2009 10:09   

pic18f usb tutorial


jumper2high wrote:

So, a revised question: Does anyone know a USB/PIC18F4550 based tutorial/demo that actually works out of the box, or contains instructions on how to make it work properly? really tried hard to find one, but only ended up with a slightly elevated blood pressure. Neutral


Hi, your posts are indeed too long!!! I didn't read everything, that way I'm asking you this: 1. do you got a custum board with the PIC18F4550?
2. if you got a Microchip board (PICDEM FS....) then you can use the demos
installed with the framework 2.4 for example. They are all working.
3. if you got a custom board, is it enumerating? if it's enumerating, which
demo did you used (HID, CDC...)?
4.if you use the Generic HID demo,then you can add your code in
PROCESSIO() and tell the microcontroller do everything you want.
Ok, I stop here, if I don't want my post to be as long as yours. Very HappyVery Happy

Best regards
Kabanga
Back to top
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post28 May 2009 16:09   

program to configure pic18f4550 as usb device


Haha, thanks for the info. I managed to get it working, I was using a custom "test circuit" and I neglected to add a capacitor on Vusb. Once I did that, a few examples worked for me, including the Microchip's spinning mouse.


Now, since that is working quite nicely (I know enough data to customize the code for what I need), all I need to figure out is how to write the PC application to handle the communication between the PIC and the data source (through IPC).

I tried using libusb-win32, and tried the example code that came with it, but I didn't get far. It seems the supplied functions don't return anything (should return a list of devices on a buss but they just return NULL). Any hints?

I'm trying to avoid working with Visual C++ and Microsoft DDK/WDK if possible.
Back to top
asmo



Joined: 26 May 2009
Posts: 4


Post20 Jun 2009 14:29   

pic usb book


hi..
still have problem with USB 18F4550?
IF YES reply here, i will explain you, make it easy once for all.
thks.
Back to top
jumper2high



Joined: 24 May 2009
Posts: 62
Helped: 3
Location: Serbia


Post20 Jun 2009 15:29   

pic18f cdc


I'd be quite happy to hear what you have to say Smile
Back to top
elrayes



Joined: 03 Jun 2008
Posts: 165
Helped: 8
Location: Egypt


Post21 Jun 2009 12:14   

pic18f4550 usb example


you can use microchip USB frame work from microchip,they are ready made USB firmwares for many PIC families and a firmware for PC18F4550 is available:
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en540668

start with CDC firmware, it will be easy in interfacing from the PC side.

good luck Smile
Back to top
asmo



Joined: 26 May 2009
Posts: 4


Post04 Jul 2009 1:52   

pic18f usb examples


Sorry for being late to reply..
first of all, don't think i am an expert.i just wanted to help anyone who will read this and who needs this little help..
second:
if you work or program using USB, you need some tools:
-When working using USB, you should see what happening there,(traffic) between the PC and the device, this will be accomplished if you have this tool: USBTrace.download it from here www.sysnucleus.com
-You should have visual c++, or basic (v6).
-You should have mikroC compiler
-You should have easyHid .In 2 mn you will be able to comunicate with the device.download it from here:http://www.mecanique.co.uk/code-studio/
download MicroCode Studio,install it,look in the installation folder,there you will find "easyHid".
-To understand once for all how to configure PIC18F4550 when using it in USB,take a look at this link: http://users.edpnet.be/rosseel01/DRO/PIC/18F2455_2550_4455_4550_Usb_Clock.htm
====> all listed programs are free to use(or limited),in a little time you will have everything ready,just read the following to know what you will do to program PIC18F4550:
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> PIC18F4550 and USB - help needed
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
USB interface with PIC18F4550.... help please. (2)
Help..!! Usb Data Acquisition with pic18f4550 (1)
Connection USB PIC18F4550 and Nokia 6230B (8)
Problem with HID USB (PIC18F4550 and EasyHID) (3)
HidLibrary.dll problem for C# and PIC18F4550 usb interface (1)
problem using timers with PIC18F4550, help needed? (5)
USB and LAN help needed !! (1)
CAN - USB interface hardware and software help needed (6)
USB Composite device on PIC18F4550 (1)
USB Driver for PIC18F4550 (5)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS