PIC 18F4550 USB communication with PC

General discussion on mikroC.
Post Reply
Author
Message
proUsb
Posts: 2
Joined: 31 May 2010 08:30

PIC 18F4550 USB communication with PC

#1 Post by proUsb » 31 May 2010 08:40

Im using the given circuit design in MikroC to communicate with PC using USB. But it doesn't work correctly. PC doesn't identify it. I'm using 20 Mhz oscillator instead of 8 Mhz....

Any Help .. ??? :?: :(

phil31
Posts: 348
Joined: 02 Apr 2009 15:02
Location: France
Contact:

Re: PIC 18F4550 USB communication with PC

#2 Post by phil31 » 31 May 2010 15:30

"Hello" .. "Please" ... "Thanks" ... never ?

if you want some help .. give us more details!

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

Re: PIC 18F4550 USB communication with PC

#3 Post by Dany » 31 May 2010 19:30

proUsb wrote:Im using the given circuit design in MikroC to communicate with PC using USB. But it doesn't work correctly. PC doesn't identify it. I'm using 20 Mhz oscillator instead of 8 Mhz....
Can you show us please the "Edit Project" (= configuration bits) values and the MCU speed in the "Project Settings" that you use?
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)

basicbasic111
Posts: 127
Joined: 26 Jan 2010 17:01

Re: PIC 18F4550 USB communication with PC

#4 Post by basicbasic111 » 01 Jun 2010 06:50

so true


more details and learn how to say " Please" and " Thanks"!!!

proUsb
Posts: 2
Joined: 31 May 2010 08:30

Re: PIC 18F4550 USB communication with PC

#5 Post by proUsb » 21 Jun 2010 19:10

phil31 wrote:"Hello" .. "Please" ... "Thanks" ... never ?

if you want some help .. give us more details!
I'm really sorry about that .. :) i was in a hurry so jst typed it.. pls apologise me.
Thank you all for your replies.

when I plug the USB connector to the PC it says device not recognised. I want to know some details about creating the usbdsc.h file too.

Thanks

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: PIC 18F4550 USB communication with PC

#6 Post by slavisa.zlatanovic » 22 Jun 2010 10:24

Hi!
PC doesn't identify it. I'm using 20 Mhz oscillator instead of 8 Mhz....
When using the 20Mhz crystal you should set the 96MHz PLL Prescaler to 5.
config.JPG
config.JPG (78.68 KiB) Viewed 4963 times
I want to know some details about creating the usbdsc.h file too.
What exactly?
Also, I recommend the Jan Axelson's book "USB complete" as one of the best USB manuals ever.
http://www.lvr.com/usbc.htm

Best regards
Slavisa
Best regards
Slavisa

BlackBird
Posts: 6
Joined: 22 Jun 2010 22:19

Re: PIC 18F4550 USB communication with PC

#7 Post by BlackBird » 23 Jun 2010 20:49

Hi people, :D

I'm getting my first steps on USB lane and I'm having the same troubles as USBpro.
I've compiled two examples given on this forum and thy did not work any way. :(
The problem still the same: PC (windoes) does not recognize the microcontroller usb port.

Details: :shock:

MikroC 8.2 version
Microcontroller: PIC18F2550
HS Quarz freq: 12 M

Selected configuration words: (only values turned ON)
1L:
PLLDIV_3 -->To obtain 4MHz from 12MHz Quarz
USBDIV_2 ---> able to clock transceiver from 96MHz by 2

1H:
FOSC_HSPLL_HS
FCMEM_ON
IESO_ON

2L:
PWRT_OFF
BOR_ON_ACTIVE
BORV_43
VREGEN_ON

2H:
WDT_OFF

3H & 3L:
MCLRE_ON
LPT1OSC_OFF
PBARDEN_OFF
CCP2MX_OFF

4L:
STVREN_OFF
LVP_OFF
ICPRT_OFF
XINST_OFF
DEBUG_OFF

The other words remain as is.

And here is the code I´ve tried, taken from a "working" example in the forum and with some modifications done by me (basically on MCU ports configuration).
___________________________________________
#include "USB_New"

unsigned char Read_buffer[64];
unsigned char Write_buffer[64];
unsigned char num, Flags;

/* Timer interrupt service routine */

void interrupt()
{
HID_InterruptProc(); /* Keep alive */

}

/* Start of MAIN program */

void main()
{

/* Disable all interrupts */
INTCON = 0; /* Disable GIE, PEIE, TMR0IE,INT0IE,RBIE */
INTCON2 = 0xF5;
INTCON3 = 0xC0;
RCON.IPEN = 0; /* Disable Priority Levels on interrupts */
PIE1 = 0;
PIE2 = 0;
PIR1 = 0;
PIR2 = 0;


/* Ports Configuration */

PORTA=0;
ADCON0=0x0; /* A/D disconnected. */
CMCON =0x7;
ADCON1=0x0F; /* Port A is a Digital port */
TRISA=0; /*Port A as output */

PORTB=0;
TRISB=0x01; /* PB0 - EXT interruption IN. All the other pins programmed as outputs*/
//INTCON=0x90; /* GIE=1, PEIE=0, INT0IE=1*/
//INTCON2=0x80; /* All PB pull-up disable, INT0 ocurres on falling edge */

PORTC=0;
UCON.F3=1; /* RC4 and RC5 configured as DI and USB module was enabled */
UCFG.F3=0; /* On-chip USB transceiver was enabled */
TRISC=0x0; /* RC7..RC4 were configured as DI, the other pins as outputs */


Flags=0x03; /* Mute-Disabled, ZCross-Enabled */
PORTB.F7=1; /* Mute - Disable */
PORTB.F6=1; /* Zero Crossing - Enable */
PORTB.F5=1; /* CS signal - Disable */



Hid_Enable(&Read_buffer, &Write_buffer);
Delay_ms(250);
Delay_ms(250);

// Read from the USB port. Number of bytes read is in num


while(1)
{
num = Hid_Read();
if(num > 0){
if((Read_buffer[0] == 'P') && (Read_buffer[1] == '=') &&
(Read_buffer[2] == '?') && (Read_Buffer[3] == '?'))
{
PORTA.F0 = 0x01;
Write_buffer[0] = 'P'; Write_buffer[1] = '=';
Write_buffer[2] = 'T'; Write_buffer[3] = 'T';
Write_buffer[4] = 'A';Write_buffer[5] = 'R';
Hid_Write(&Write_buffer,6);
}
}
delay_ms(80);
PORTA.F0 = 0;
num = 0;

} //end while (1)
Hid_Disable();
}//end miain

¿Somebody could tell me what´s wrong here? :?

Also I want to ask for information about how the HID terminal works. Indeed on the MikroC 8.2 HELP nothing is written. :o

Thanks a lot, :mrgreen:

Black Bird
Attachments
Bits2550.PNG
Bits2550.PNG (28.5 KiB) Viewed 4944 times

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

Re: PIC 18F4550 USB communication with PC

#8 Post by Dany » 26 Jun 2010 15:05

Hi, there are several things not correct in the configuration file (a.o. the clock frequency, which should not be set to the crystal frequency but to the MCU clock speed), please have a look into:
http://users.edpnet.be/rosseel01/DRO/PI ... %20Old.htm to obtain the correct ones for use with an older mC version (as you do apparently).
Selected configuration words: (only values turned ON)
1L:
PLLDIV_3 -->To obtain 4MHz from 12MHz Quarz
USBDIV_2 ---> able to clock transceiver from 96MHz by 2
- CPUDIV_OSC1_PLL2 should also be checked (gives you an 48 Mhz CPU clock)
Hid_Enable(&Read_buffer, &Write_buffer);
Delay_ms(250);
Delay_ms(250);
Delay should be 2 times 1000 ms.

Furthermore: you use an old version of mC, the configuration settings screen is different from that one of the newest version.
For documentation on the newest version, see http://users.edpnet.be/rosseel01/DRO/PI ... _Clock.htm.

Good luck!
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)

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

Re: PIC 18F4550 USB communication with PC

#9 Post by Dany » 26 Jun 2010 15:30

slavisa.zlatanovic wrote:Hi!
PC doesn't identify it. I'm using 20 Mhz oscillator instead of 8 Mhz....
When using the 20Mhz crystal you should set the 96MHz PLL Prescaler to 5.
config.JPG
I want to know some details about creating the usbdsc.h file too.
What exactly?
Also, I recommend the Jan Axelson's book "USB complete" as one of the best USB manuals ever.
http://www.lvr.com/usbc.htm

Best regards
Slavisa
USB voltage regulator disabled?
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”