View previous topic :: View next topic |
Author |
Message |
Squintz
Joined: 08 Dec 2009 Posts: 11
|
PIC18F4550 USB Internal Pull-up Full Speed |
Posted: Mon Sep 13, 2010 2:17 pm |
|
|
I'm using the PIC18F4550. Can someone tell me how to make sure the USB D+ Internal Pull Up resistor is enabled? I see in the data sheet that it's there but I'm not sure how to code this for CCS.
I'm using the default usb_cdc.h, usb.h, usb_desc_cdc.h, usb_hw_layer.h pic18_usb.h header files.
I see that in the pic18_usb.h header there is a comment that says the pull ups are enabled using "this code" but I don't see where it's explicitly doing that. So I would like to do it myself to make sure its enabled. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 13, 2010 5:41 pm |
|
|
Look at these two routines in the pic18_usb.c driver. Notice that they
write directly to the USB Config Register (UCFG) in the 18F4550. This is
how the internal pullups are either enabled or disabled.
Code: |
void usb_detach(void)
{
UCON = 0; //disable USB hardware
UIE = 0; //disable USB interrupts
UCFG = __UCFG_VAL_DISABLED__;
.
.
.
}
void usb_attach(void)
{
usb_token_reset();
UCON = 0;
UCFG = __UCFG_VAL_ENABLED__;
.
.
.
}
|
Look at this diagram in the 18F4550 data sheet:
Quote: | REGISTER 17-2: UCFG: USB CONFIGURATION REGISTER |
It shows that bit 4 is the UPUEN bit, which controls the internal pullups.
Also, the FSEN bit then selects which of the two internal pullups is used.
If you look at the #define and the #ifdef statements in pic18_usb.c, then
you will see they define the mask for bit 4 of UCFG in the line below:
Quote: | #define __USB_UCFG_UPUEN 0x10
|
In the code below, from pic18_usb.c, they have an interesting block.
They have two #if defined() statements that check if you selected internal
or external pullups. But my text search engine (Examine32) doesn't find
any instances of these two values being defined in any example file or
driver file (.c or .h). So, it seems that the 3rd section below is actually
in control, and what does it do ? It enables internal pullups. That's how
CCS can say that "this code" enables the internal pullups.
Code: |
#if defined(USB_EXTERNAL_PULLUPS)
#define __USB_UCFG_MY_UPUEN 0
#endif
#if defined(USB_INTERNAL_PULLUPS)
#define __USB_UCFG_MY_UPUEN __USB_UCFG_UPUEN
#endif
#if !defined(__USB_UCFG_MY_UPUEN)
#define __USB_UCFG_MY_UPUEN __USB_UCFG_UPUEN
#endif |
|
|
![](templates/subSilver/images/spacer.gif) |
Squintz
Joined: 08 Dec 2009 Posts: 11
|
|
Posted: Tue Sep 14, 2010 10:39 am |
|
|
Excellent Reply. Thank you! |
|
![](templates/subSilver/images/spacer.gif) |
|