|
|
View previous topic :: View next topic |
Author |
Message |
Slim PICins
Joined: 03 Feb 2016 Posts: 2 Location: Nevada,USA
|
USB_CDC enum |
Posted: Thu Feb 04, 2016 10:29 am |
|
|
Compiler 4.128
PIC18F87J50
This code allows fairly reliable enumerations (USB To UART COM10) upon cable connection, as long as I have the "delay_ms(250)" line in. If I lower the delay or remove this line, I get "Device not Recognized" or "Device won't Start".
Any ideas? Thanks
Code: | void main()
{
InitSystem();
//setup_adc_ports(NO_ANALOGS);
setup_timer_3(T3_DISABLED | T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
// Use usb_init_cs()'connection sense' instead of usb_init()
usb_init_cs(); //Original
//usb_cdc_init();//Original
do
{
if(usb_attached())
{
usb_task();
delay_ms(250);
if(usb_enumerated())
{
OUTPUT_HIGH(LED_PIN);
if((usb_cdc_carrier.dte_present) && (bEnumeratedFlag == FALSE))
{
printf(usb_cdc_putc,"Hello, Universal Controller USB!\n\r");
printf(usb_cdc_putc,"Enter ASCII command or '?'\n\r");
bEnumeratedFlag = TRUE;
}
UsbReceiveTask();
}
else
{
OUTPUT_LOW(LED_PIN);
usb_init_cs();
}
}
else
{ // The cable has been disconnected
OUTPUT_LOW(LED_PIN);
bEnumeratedFlag = FALSE;
usb_cdc_init(); //clear buffers if disconnected
}
}while(TRUE);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Feb 04, 2016 3:30 pm |
|
|
The problem is that you keep calling init_cs.
This only needs to be called once.
What is happening, is it sees the cable as attached, but it is not enumerated (yet). Your code then calls init_cs again, which resets the hardware, and prevents enumeration. So it keeps looping round not enumerating.
By adding the delay you give it time to enumerate.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|