usb 18f4550 beginer

General discussion on mikroC.
Post Reply
Author
Message
marco
Posts: 57
Joined: 03 Jan 2008 20:34

usb 18f4550 beginer

#1 Post by marco » 09 Feb 2010 13:53

hello my friends.
this week , i´m trying to start on 18f4550 , becouse of the usb.
I want to do a very simple task ,of sending one byte to pc , just to understand how it works.
I´ve tryed to use the exemple of USB HID Library, but it doe not work(Routine InitUSBdsc not defined).
Does any one have a simple example ?
I´m using mikroC v8.2 , but for interface i have HID terminal from mikroC PRO for PIC. xtal = 4MHz


thank you again for you time!

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: usb 18f4550 beginer

#2 Post by Dany » 09 Feb 2010 17:45

The main pitfalls here are the clock settings of the PIC, see http://users.edpnet.be/rosseel01/DRO/PI ... _Clock.htm. They depend on the crystal speed used and the USB speed (low or full). Do also not forget to enable Vusb of the PIC.
Also the "MCU clock" in the IDE should be set to the correct value (depend on the configuration settings above).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

marco
Posts: 57
Joined: 03 Jan 2008 20:34

Re: usb 18f4550 beginer

#3 Post by marco » 09 Feb 2010 19:28

Tanks for your fast reply !

So...if i use a 20MHz xtal,

Oscilator-------------------------HS-HS osc.
USB Int.voltage reg---------------Enable
USB clok selection----------------USBclk.from primary osc.
Sys.clok postscale----------------No postscaler
PLL Prescaler---------------------Divide by 5 (20MHZ osc.in.)
( i´m i missing any thing?)

the exemple will work???

thanks .

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: usb 18f4550 beginer

#4 Post by Dany » 10 Feb 2010 11:41

marco wrote:So...if i use a 20MHz xtal,
Oscilator-------------------------HS-HS osc.
USB Int.voltage reg---------------Enable
USB clok selection----------------USBclk.from primary osc.
Sys.clok postscale----------------No postscaler
PLL Prescaler---------------------Divide by 5 (20MHZ osc.in.)
If you want full speed USB (as I assume) you will need the PLL. This means the following:
Oscilator-------------------------HS: HS+PLL., USB-HS
USB Int.voltage reg---------------Enable
USB clok selection----------------Clock src from 96 Mhz PLL/2.
Sys.clok postscale----------------96 Mhz PLL src / 2 (*)
PLL Prescaler---------------------Divide by 5 (20MHZ osc.in.)

(*) this will give you a CPU clock of 48 Mhz (to be set in the IDE as clock speed).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

marco
Posts: 57
Joined: 03 Jan 2008 20:34

Re: usb 18f4550 beginer

#5 Post by marco » 11 Feb 2010 15:25

hello and tank you again!

I tryed this confuguration , but the exmple have the samme massege(Routine InitUSBdsc not defined).(what does it mean?)Is it just a configuration probleme??

unsigned char RD_len;

unsigned short userWR_buffer[64];
unsigned short userRD_buffer[64];


void interrupt()
{
Hid_InterruptProc();

}


void Init_Main()
{
//--------------------------------------
// Disable all interrupts
//--------------------------------------
INTCON2 = 0xF5;
INTCON3 = 0xC0;
RCON.IPEN = 0; // Disable Priority Levels on interrupts
PIE1 = 0;
PIE2 = 0;
PIR1 = 0;
PIR2 = 0;

ADCON1 |= 0x0F; // Configure all ports with analog function as digital

TRISA = 0xFF;
TRISB = 0xFF;
TRISC = 0xFF;
TRISD = 0x00;
TRISE = 0x07;

LATA = 0;
LATB = 0;
LATC = 0;
LATD = 0;
LATE = 0;



//useless on 18F4550
//--------------------------------------
// Enable PLL !!!
//--------------------------------------
//PLLEN = 1;
//Delay_mS(5);



}


void main()
{
Init_Main();

HID_Enable(userRD_buffer, userWR_buffer);

Delay_mS(1000);
Delay_mS(1000);

while(1){

RD_len = HID_Read();

//do something

}
HID_Disable();
}


Does any one has used the mikroC USB exemple???, becouse i can´t compile it.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: usb 18f4550 beginer

#6 Post by Dany » 14 Feb 2010 09:07

marco wrote:I tryed this confuguration , but the exmple have the samme massege(Routine InitUSBdsc not defined).(what does it mean?)Is it just a configuration probleme??
No, it is not a configuration problem.
The actual reason for the problem I do not know, I am a Pascal for PIC guy. In pascal this routine is in the USB descriptorfile. I assume it is similar in C and you did make one (with the help of the HID tool in the IDE)?
You will have to ask your C collegues... :oops:
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroC General”