dnz_1905
Joined: 31 Mar 2011 Posts: 2
|
USB application with 18f4550 is not enumerating. |
Posted: Thu Mar 31, 2011 9:50 am |
|
|
Firstly, I would like to thank all the contributors and moderators of "ccsinfo.com/forum" for this great website.
I am a beginner at USB communication and I want to make a simple led application with 18f4550. But I can not make it work. When I plug the USB cable, I can not get any response from the computer. Its not loading the driver.
My aim is:
When the USB cable connected, LED1(yellow) on
When its enumerated, LED2(green) on,
else LED3(red) on.
I am using 20 Mhz Crystal oscillator with two 15pf capacitors. I use the B2 pin for connection sense and I use VUSB pin with 470nF.
Here is the code, that I wrote:
Code: |
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN
#use delay (clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#DEFINE USB_HID_DEVICE true
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 255 //allocate 8 bytes in the hardware for transmission
//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 255 //allocate 8 bytes in the hardware for reception
#include <pic18_usb.h>
#include <USB.H>
#include <usb_desc_hid.h>
#include <usb.c>
#define USB_CON_SENSE_PIN PIN_B2
#define usb_attached() input(USB_CON_SENSE_PIN)
#use fast_io(d)
int8 x;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
// TODO: USER CODE!!
set_tris_d(0x00);
output_d(0x00);
usb_init();
x=0;
while(1)
{
usb_task();
if(usb_attached() && usb_enumerated())
{
output_d(0x01);
}
else if(usb_attached() && !usb_enumerated())
{
output_d(0x04);
}
else if(!usb_attached())
{
output_d(0x02);
}
}
}
|
Please help me.
Thanks |
|