CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F4550 USB Internal Pull-up Full Speed

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Squintz



Joined: 08 Dec 2009
Posts: 11

View user's profile Send private message

PIC18F4550 USB Internal Pull-up Full Speed
PostPosted: Mon Sep 13, 2010 2:17 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 13, 2010 5:41 pm     Reply with quote

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
Squintz



Joined: 08 Dec 2009
Posts: 11

View user's profile Send private message

PostPosted: Tue Sep 14, 2010 10:39 am     Reply with quote

Excellent Reply. Thank you!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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