View previous topic :: View next topic |
Author |
Message |
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
[SOLVED] - 18f47j53 and usb |
Posted: Wed Nov 18, 2015 3:33 am |
|
|
Hi all
I try to make usb working on 18f47j53 (usb to serial).
In datasheet writes that internal osc is quite accurate and can be used for usb communication so i try this without crystal.
When i plug it on win xp machine that has already work with 18f4550 usb module, it doesnt find it at all.
There is nothing in the code but usb initiation.
Code: |
#include <main.h>
void main()
{
usb_init();
while(TRUE)
{
//TODO: User Code
output_toggle(status_led);
delay_ms(500);
}
}
|
The led is there to see that board is alive,
and in main.h i have this
Code: |
#include <18F47J53.h>
#device ADC=12
#FUSES intrc_pll_io
#FUSES pll2
#FUSES pllen
#FUSES NOWDT //No Watch Dog Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PROTECT //Code protected from reads
#FUSES SOSC_DIG //Digital mode, I/O port functionality of RC0 and RC1
#FUSES CLOCKOUT //Output clock on OSC2
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES DSWDTOSC_INT //DSWDT uses INTRC as reference clock
#FUSES RTCOSC_INT //RTCC uses Internal 31KHz Oscillator as reference source
#FUSES DSBOR //BOR enabled in Deep Sleep
#FUSES DSWDT //Deep Sleep Watchdog Timer enabled
#FUSES DSWDT2147483648 //DSWDT uses 1:2147483648 Postscale
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
#FUSES ADC10 //ADC is 10-bits
#FUSES MSSPMSK7 //MSSP uses 7 bit Masking mode
#FUSES WPFP //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES WPCFG //Configuration Words page is erase/write-protected
#FUSES WPDIS //All Flash memory may be erased or written
#FUSES WPEND //Flash pages WPFP to Configuration Words page are write/erase protected
//#use delay(internal=24MHz)
#use delay(clock=48MHz)
#define USB_CONFIG_BUS_POWER 500
#define Status_led PIN_c0
#include <usb_cdc.h>
|
which is actually my last attempt. I tried on 24MHz too with pullup resistor on the correct side of usb signal but nothing at all.
Any hint???
Last edited by nuclear__ on Fri Nov 20, 2015 3:23 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Nov 18, 2015 3:52 am |
|
|
The internal clock is _not_ accurate enough......
What it has is an ability to phase lock onto the USB signal when connected, to give the accuracy required.
'Active clock tuning'.
This has to be enabled.
You have got half way there (INTRC_PLL_IO), enables the PLL.
However you also have to say what the internal oscillator is to synchronise to. The PLL, can be operated from other things than the USB. This is beautifully 'non documented' in CCS, but you need:
#use delay(int, clock=48MHz, USB_FULL, act=USB)
Which says 'use the internal oscillator'. At 48MHz, With the clock all setup for USB full speed operation, and synchronised from the USB.
One day, the manual will be updated (I hope...).
There is also a separate option to do this with 'setup_act'.
setup_act(ACT_ENABLED | ACT_TUNED_TO_USB);
Again tells the active clock tuning to tune to the USB.
This one was in a 'readme' a few versions ago, but never seems to have reached the manual. |
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Thu Nov 19, 2015 2:42 am |
|
|
Thank you Ttelmah. Unfortunately it didn't work. It still not visible to pc at all.
Should I configure anything else so c4 c5 will be used as usb lines?
My hardware is like that
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Nov 19, 2015 3:13 am |
|
|
Step back.
First, have you actually checked the chip is running, and at the expected speed?. The old 'flash an LED' test.
It is always worth making sure the hardware is doing what is expected, before getting into more complex debugging....
Then you have the connection sense pin in your hardware, so set the code up to use it. Change your USB load lines to:
Code: |
#define USB_CABLE_IS_ATTACHED() input(PIN_D3)
#include <usb_cdc.h>
|
The CCS code used to always default to using pin B0, if it was not explicitly told not to, and it is possible it is doing so. This would stop the USB from initialising. The 'USB_CABLE_IS_ATTACHED' macro is required, and normally generated for you by ex_usb_common.h, from the 'PIN_USB_SENSE' pin number. If the pin is not present, it is meant to be dummied out as a permanently 'TRUE', but if this was not happening, the USB peripheral won't be waking up.
I'd get rid of your other clock fuse settings. The 'automatic' compiler ones should work on current compilers and it is possible that something is getting confused by having two sets.
Then try adding a short delay at the start. In ex_usb_common.h, the example using the internal oscillator with sync (PIC18F67J94), has an extra delay at boot of 72mSec, with the comment 'wait for PLL to get stable'. Trying to initialise the USB too early could also be causing a problem. |
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Thu Nov 19, 2015 3:38 pm |
|
|
Led blinks on time. I added USB sense Line and 200ms delay. It still not working. The only difference is that if i don't plug the USB cable, led is not blinking too, it looks frozen. I guess i should try that with an oscillator. Do you have any other idea?
Could that be hw problem? in other trials i did with other mcus i can remember that pc always were finding unknown device, and it was up to program and drivers to make it work. But now there is no reaction. |
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
OK!! |
Posted: Thu Nov 19, 2015 4:36 pm |
|
|
It was a faulty cable!!
i plug it to my phone to get some foto. Then i saw that it only charge it but no data...... I replaced it and now Works!
Thank you very much for your time. I learnt some things from you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Nov 20, 2015 2:26 am |
|
|
Flag the post as 'solved' (edit the post header).
Glad you got it. |
|
|
|