PDA

View Full Version : Need Help with USB using PIC18F2455



iugmoh
- 14th April 2008, 20:19
I use EasyHID to generate both PICBASIC code and visual basic code, I connected the cicuit as shown in various posts and schematics, but evey time I plug the usb cable in our laptop or my PC I have a problem "USB Device Not recognized" , I sure that I'm connected the circuit well with 470nF capacitor but the same problem , I think there are a driver I must install or something else.
I attached my photos for clearing

mister_e
- 14th April 2008, 20:32
Most problem comes with the ConfigFuse setting, then the code. Is it me.. or i don't any of those here? ;)

You'll also need to tell us which crystal/resonator speed you have.

I saw you looked at USBDemo... you didn't find anything to use in? :(

iugmoh
- 14th April 2008, 21:05
Oky here is my code which I use 4MHZ crystal:

' Pic Configuration
' =================
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)


__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB

__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm

DEFINE OSC 48
;DEFINE LOADER_USED 1
symbol led=portb.7
output led
USBBufferSizeMax con 8 ' maximum buffer size
USBBufferSizeTX con 8 ' input
USBBufferSizeRX con 8 ' output

' the USB buffer...
USBBuffer Var Byte[USBBufferSizeMax]
USBBufferCount Var Byte

' ************************************************** **********
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************** **********
low led
usbinit ' initialise USB...
ProgramStart:

gosub DoUSBIn
toggle led
pause 100
gosub DoUSBOut
toggle led
pause 100
goto ProgramStart

' ************************************************** **********
' * receive data from the USB bus *
' ************************************************** **********
DoUSBIn:
USBBufferCount = USBBufferSizeRX ' RX buffer size
USBService ' keep connection alive
USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available
return

' ************************************************** **********
' * wait for USB interface to attach *
' ************************************************** **********
DoUSBOut:
USBBufferCount = USBBufferSizeTX ' TX buffer size
USBService ' keep connection alive
USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
return

mister_e
- 14th April 2008, 21:10
this section will cause you a problem


gosub DoUSBIn
toggle led
pause 100
gosub DoUSBOut
toggle led
pause 100
goto ProgramStart

Why? because of this section

' ************************************************** **********
' * main program loop - remember, you must keep the USB *
' * connection alive with a call to USBService every couple *
' * of milliseconds or so... *
' ************************************************** **********

The easy way will be to use Darrel's instant interrupts. Here's the famous POST 148
http://www.picbasic.co.uk/forum/showpost.php?p=30682&postcount=148

iugmoh
- 14th April 2008, 21:18
Iam from begining not include delay of 100ms but I added them to give indication for led about where the code stuck and find that It's stuck in DousbIn subroutine. now I'm removed the delay time and the same problem , I don't know where is the problem ????????????

mister_e
- 14th April 2008, 21:32
DoUSBIn:
USBBufferCount = USBBufferSizeRX ' RX buffer size
USBService ' keep connection alive
USBIn 1, USBBuffer, USBBufferCount, TimeOut ' No data?, Getout of here
TimeOut:
return

Do you still have the USB connection error?

Maybe better to begin with USBDemo and work around with? There's a load of information in that thread (ok ~180 post to read but)

iugmoh
- 14th April 2008, 22:09
I have the same problem I can't use your USBDEMO since I don't have pic18f4450 but I have pic18LF445, so in microcode when I switch to this model I have compile error

ERROR: Macro USBINIT? not found in macro file.
ERROR: Macro USBSERVICE? not found in macro file.
ERROR: Macro USBIN?CBBL not found in macro file.
ERROR: Macro USBOUT?CBBL not found in macro file.

mister_e
- 14th April 2008, 22:28
You must mean 18F4455, so just use the files in attachment. Tested and work as expected here. i just forgot to change the device name in the top comments...

@Darrel... link to this one too :D

iugmoh
- 14th April 2008, 22:47
There is an error:
ERROR Line 78: Syntax error. (USBDemo_4455.pbp)

this line : UCFG = %00010100 ' enable internal USB pull-up, Full speed USB


but when I comment it , it's compiled without any errors

mister_e
- 14th April 2008, 22:51
HA! so that mean you may use V2.47 of the compiler right?

I thought i would remove the

UCFG var byte EXT
line because some had 'Redefinition of VAR' problem with V2.50.. anyways, it should work, unless you know what else to add ;)

I'm a bit mixed-up... your thread name is Need Help with USB using PIC18F2455 :o

iugmoh
- 14th April 2008, 23:00
yes I'm use PBP247 , oky I compile and load the hex file but the same problem

I have some questions:
1)Can I use any type of the 470nF capacitor because I'm not use ceramic I use mica
2) Does I need special way to load my hex file to pic or any programmer, I use superpro 280U programmer.

mister_e
- 14th April 2008, 23:16
You shouldn't have any problem with mica cap.

In your device programmer software you may have an option to program the config fuses setting or not. I don't have this specific programmer and seems their software refuse to install on my machine... so i can't really help you on that.

Have you already program other PICs with this one?

iugmoh
- 15th April 2008, 07:31
I don't have any problems with this programmer , I used it many times and it has a high performance , and you can set config fuses using programmer software or from PICBASIC , and here we add them using picbasic so it's updated automatically in programmer software
I will attach the configuration fuses photos

' Pic Configuration
' =================
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)


__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB

__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm

iugmoh
- 15th April 2008, 09:28
anyone can help ??

iugmoh
- 15th April 2008, 10:52
Oky now It's working fine , I discover the problem is from connector is not soldering perfectly with wires so I cut the connector cable and connect it directly and working fine

mister_e
- 15th April 2008, 15:56
;) yeah it happen :D

Since it's a high level programmer (645$) I was a bit worried about why on earth it doesn't work... Glad to hear you find it!

iugmoh
- 15th April 2008, 16:58
thanks mister but I want to ask why using assembly code in PICBASIC code for usb , is't not possible to do this without assembly code

mister_e
- 15th April 2008, 17:07
Why... personal choice i guess, i had fun... (yes Darrel... i was in a good MOON... happy now ;) )

But yes it's possible, the only few line of asm you need to keep are the config fuses... the others can be replaced with regular PBP lines.