|
|
View previous topic :: View next topic |
Author |
Message |
Zezem
Joined: 02 Mar 2017 Posts: 7
|
USB CDC Help |
Posted: Mon Mar 06, 2017 2:31 pm |
|
|
So I've been trying to get this pretty basic CDC project working but have ran out of ideas.
INFO:
PIC: 18F4550
Crystal 8 MHZ
Microchip Explorer 8 Dev Board
I think my fuses aren't set up right... I can't seem to get past usb_enumerated()
THANKS ALOT
Code: |
#include <18f4550.h>
#include "globals.h"
#include<usb.h>
#include<usb_cdc.h>
#include <pic18_usb.h>
#include <stdlib.h>
#fuses HSPLL //High Speed Crystal/Resonator with PLL enabled
#fuses NOPROTECT //Code not protected from reading
#fuses NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#fuses NODEBUG //No Debug mode for ICD
#fuses USBDIV //USB clock source comes from PLL divide by 2
#fuses CPUDIV1 //No System Clock Postscaler
#fuses PLL5 //PLL5 Divide By 5(20MHz oscillator input)
#use delay(clock = 48Mhz,USB_FULL)
//Set up UARTs.
#use rs232(UART1, baud=9600, errors)
//#use rs232(baud=9600, errors)
//#use rs232(baud=1000,FLOAT_HIGH,xmit=PIN_B0,rcv=PIN_B0)
void main(void) {
usb_init(); //used to init usb port with a device that powers itself. same as usb_init otherwise.
usb_cdc_init(); //
int1 usb_cdc_oldconnected=FALSE;
int i = 0;
int new_connected;
int new_enumerated;
int new_cdc;
while(TRUE)
{
if(usb_attached())
{
usb_task();
if(usb_enumerated())
{
if(usb_cdc_carrier.dte_present)
{
if(usb_cdc_oldconnected == FALSE)
{
printf(usb_cdc_putc,"Hello World!\n\r");
usb_cdc_oldconnected = TRUE;
}
if(usb_cdc_kbhit())
{
usb_cdc_putc(toupper(usb_cdc_getc()));
}
}
}
}else
{
usb_cdc_oldconnected = FALSE;
usb_cdc_init();
}
}
return;
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Mar 06, 2017 2:50 pm |
|
|
1) Fuses & clock should be above all the includes, except for the processor one.
The general layout in CCS C should always be:
Processor define or include
#DEVICE statements
#FUSE
#USE DELAY
#PIN SELECT's (if chip uses PPS)
#USE statements
Then includes
Then code.
Code included before clock statements, will often not function correctly...
2) Do you have a USB_ATTACHED connection?.
This is _required_ by USB, unless the device is powered from the USB cable. Usb_attached _wants_ this.
3) Generally keep to the original C standard, and declare variables at the start of code sections. Though CCS will accept them later, this can cause unexplained problems. It's a case of "keep to the standard, it's safer".
4) You have the code setup for a 20MHz crystal. It says this in the comments, yet you have an 8Mhz crystal. You need PLL2 for an 8MHz crystal. |
|
|
|
|
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
|