|
|
View previous topic :: View next topic |
Author |
Message |
MiniMe
Joined: 17 Nov 2009 Posts: 50
|
USB 18F4550 not recognized by PC |
Posted: Fri Nov 04, 2016 4:05 pm |
|
|
Hi!
There is a problem in a hobby project from years ago. USB is not working. I am afraid that the configuration is not correct.
What I have done:
- Reduced program to minimum
- Tried several configurations for USB
- Ensured that delay by delay_ms(1000) is ~1 sec according to observations.
Header file:
Code: |
#include <18F4550.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
//#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES XTPLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //**Internal External Switch Over mode enabled
#FUSES NOFCMEN //**Fail-safe clock monitor enabled
#FUSES NOPBADEN //**PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV3 //System Clock by 4 // 3 = 4 96 / 4 = 24 Mhz
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES HS
//#FUSES NOICPRT //**ICPRT enabled
//-------------------------------
//#define RTCC_PRELOAD (256 - 39)
#define RTC_SDA PIN_C1
#define RTC_SCL PIN_C0
//------------------------------
//#use I2C(MULTI_MASTER,sda=RTC_SDA, scl=RTC_SCL)
//s#use delay(clock=24MHz, crystal=4MHz, USB_LOW)
#use delay(clock=48MHz, crystal=4MHz, USB_FULL)
#use rs232(uart1, baud=9600 ,XMIT=PIN_C6, RCV=PIN_C7 )
//------------------------------
|
Program file:
Code: |
#include "main EC-12M.h"
#OPT 9
//USB glob vars
//#define USB_CON_SENSE_PIN PIN_B2
//#define USB_OPT_FOR_ROM 1
#include <stdlib.h>
#include <usb_cdc.h>
void main(){
UNSIGNED int32 counter = 0;
//USB_init
usb_cdc_init(); // Start cdc
usb_init(); // Start USB
//usb_init_cs(); // vb parem varian kui ylemine
WHILE(TRUE){
printf(" % Lu / n / r", counter);
usb_task();
IF(usb_enumerated()){
delay_ms(500);
output_low(PIN_D7);
delay_ms(500);
output_high(PIN_D7);
printf(usb_cdc_putc, " % Lu", counter);
//usb_cdc_putc_fast
delay_ms(100);
}
counter++;
}
}
|
Schematic
Questions:
-Could it be a hardware problem?
-Could it be a PC problem (tried 2 PCs)
-What are the check i have to make to narrow down the problem.
Tests were conducted on actual soldered PCB and in Proteus ISIS simulation environment.
The spaghetti code which I wrote worked very long time ago. ~4-5 years. . I did not know how to use auto formatter then. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Nov 04, 2016 4:55 pm |
|
|
First, I would confirm the PIC is operational by coding a '1Hz LED' program and seeing that work. This will show the hardware is 'probably' OK.
Second, 4-5 years is a LONG time. If this program did work back then and the PIC hardware has never been changed then the only source of problem will be the PC. ANY upgrade in the operating system can and will affect if IT can see the PIC.
If the correct USB driver is installed a program like USBVIEW should see the PIC.
You say you've made changes to the old working program. Hopefully you have a copy of one that DID work, use that as a reference after the 1Hz LED program works.
These are general comments, as I no longer use the '4550' PIC. It was easier/faster/cheaper to use a USB<>TTL module.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Sat Nov 05, 2016 4:20 am |
|
|
These lines conflict with one another:
Code: |
#FUSES CPUDIV3 //System Clock by 4 // 3 = 4 96 / 4 = 24 Mhz
#use delay(clock=48MHz, crystal=4MHz, USB_FULL)
|
For your clock statement as posted, you want CPUDIV1.
Also get rid of HS. You have XTPLL selected as well. For a 4MHz crystal, you just want XTPLL.
Add 'ERRORS' to your RS232 setup. This should always be used on the
hardware UART, unless _you_ are adding your own error code. Can get the chip hung if it is not there....
Then you are printing to the port, when there may be nothing there to receive the data. Being 'enumerated' does not mean the port is 'open'....
So code becomes:
Code: |
#include <18F4550.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES XTPLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //brownout reset - should be used
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //**Internal External Switch Over mode enabled
#FUSES NOFCMEN //**Fail-safe clock monitor enabled
#FUSES NOPBADEN //**PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV1 //System Clock 48Mhz
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
//-------------------------------
//#define RTCC_PRELOAD (256 - 39)
#define RTC_SDA PIN_C1
#define RTC_SCL PIN_C0
//------------------------------
#use delay(clock=48MHz, crystal=4MHz, USB_FULL)
#use rs232(uart1, baud=9600 ,XMIT=PIN_C6, RCV=PIN_C7, ERRORS )
//------------------------------
#include <stdlib.h>
#include <usb_cdc.h>
void main(void)
{
UNSIGNED int32 counter = 0;
enable_interrupts(GLOBAL);
//USB requires the global interrupt enabled, unless _you_
//are polling usb_task at least 1000* per second
usb_cdc_init(); // setup cdc
usb_init_cs(); // Start USB when CS
WHILE(TRUE)
{
printf(" % Lu / n / r", counter);
usb_task();
if (usb_enumerated())
{
//Problem here is you are printing to an enumerated port
//that may not be open. The enumeration occurs as soon as
//the device is attached. The port only 'opens' when a program
//actually attaches to it....
if (usb_cdc_carrier.dte_present)
{
printf(usb_cdc_putc, " % Lu", counter); //send when open
delay_ms(500);
output_low(PIN_D7);
delay_ms(500);
output_high(PIN_D7);
}
}
counter++;
}
}
|
If you look at the CCS examples, they only print to the port, once something has been received. The code here shows how to print automatically when the port is opened. |
|
|
|
|
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
|