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 support@ccsinfo.com

Usb connection and PIC18F4550
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
K-BoSS



Joined: 03 Sep 2007
Posts: 6

View user's profile Send private message

Usb connection and PIC18F4550
PostPosted: Mon Sep 03, 2007 2:04 pm     Reply with quote

Hi mates

I am trying to connect the Pic 18f4550 using the sample ccs code ex_usb_serial.c to make a virtual rs232 connection.
I can compile and program the pic without errors, but i don´t know if i must install a driver or what because when i connect the pic to the computer the windows doens´t detect the hardware and let me no choice of driver to choose.

Here is the code that i am trying ...


Code:
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
////                        ex_usb_serial.c                          ////
////                                                                 ////
//// A demonstration of the USB CDC API that is provided by CCS.     ////
//// The USB CDC API that CCS provides will create a virtual UART    ////
//// port.  USB CDC drivers are included with most versions of       ////
//// Microsoft Windows, and when properly loaded will create a COMx  ////
//// port from which you can write and read to your PIC device       ////
//// like any serial device that has a COMx port.                    ////
////                                                                 ////
//// This example creates a USB<->UART converter.  Open              ////
//// Hyperterminal to COM1 (or whatever COM port is your usual RS232 ////
//// serial COM port).  Plug the PIC to USB.  Open Hypertimernal to  ////
//// the new COM port that is the USB<->UART COM port (for this      ////
//// example say it is COM2).  Typing a character in COM1 will cause ////
//// it to be sent out COM2, and vice-versa.                         ////
////                                                                 ////
//// See usb_cdc.h for API documentation.                            ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
//// VERSION HISTORY                                                 ////
////                                                                 ////
//// July 1st, 2005: Initial Release.                                ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2005 Custom Computer Services         ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////

//set to 1 to use a PIC's internal USB Peripheral
//set to 0 to use a National USBN960x peripheral
#define __USB_PIC_PERIF__ 1

#if !defined(__PCH__)
 #error USB CDC Library requires PIC18
#endif


#if __USB_PIC_PERIF__
 #DEFINE LED1  PIN_A5
 #include <18F4550.h>
 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
 #use delay(clock=48000000)
#else //use the National USBN960x peripheral
 #DEFINE LED1  PIN_B3
 #include <18F452.h>
 #fuses HS,NOWDT,NOPROTECT,NOLVP
 #use delay(clock=20000000)
#endif   //endif check to see which peripheral to use

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

/////////////////////////////////////////////////////////////////////////////
//
// If you are using a USB connection sense pin, define it here.  If you are
// not using connection sense, comment out this line.  Without connection
// sense you will not know if the device gets disconnected.
//       (connection sense should look like this:
//                             100k
//            VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
//                     |
//                     +----/\/\/\/\/\-----GND
//                             100k
//        (where VBUS is pin1 of the USB connector)
//
/////////////////////////////////////////////////////////////////////////////
///only the 18F4550 development kit has this pin
#if __USB_PIC_PERIF__ && defined(__PCH__)
 #define USB_CON_SENSE_PIN PIN_B2
#endif


#include <usb_cdc.h>

/////////////////////////////////////////////////////////////////////////////
//
// Configure the demonstration I/O
//
/////////////////////////////////////////////////////////////////////////////
#define LED2 PIN_B4
#define LED3 PIN_B5
#DEFINE BUTTON PIN_A4
#define LED_ON output_low
#define LED_OFF output_high


/////////////////////////////////////////////////////////////////////////////
//
// usb_debug_task()
//
// When called periodically, displays debugging information over serial
// to display enumeration and connection states.  Also lights LED1 based upon
// enumeration and status.
//
/////////////////////////////////////////////////////////////////////////////
void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;
   static int8 last_cdc;
   int8 new_cdc;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();
   new_cdc=usb_cdc_connected();

   if (new_enumerated)
      LED_ON(LED1);
   else
      LED_OFF(LED1);

   if (new_cdc)
      LED_ON(LED2);
   else
      LED_OFF(LED2);

   if (usb_cdc_carrier.dte_present)
      LED_ON(LED3);
   else
      LED_OFF(LED3);

   if (new_connected && !last_connected)
      printf("USB connected, waiting for enumaration...\r\n\n");
   if (!new_connected && last_connected)
      printf("USB disconnected, waiting for connection...\r\n\n");
   if (new_enumerated && !last_enumerated)
      printf("USB enumerated by PC/HOST\r\n\n");
   if (!new_enumerated && last_enumerated)
      printf("USB unenumerated by PC/HOST, waiting for enumeration...\r\n\n");
   if (new_cdc && !last_cdc) {
      printf("Serial program initiated on USB<->UART COM Port\r\n\n");
      printf(usb_cdc_putc, "\r\n\nCCS CDC (Virtual RS232) Example\r\n\n");
   }

   last_connected=new_connected;
   last_enumerated=new_enumerated;
   last_cdc=new_cdc;
}

void main(void) {
   char c;

   LED_OFF(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);

   printf("\r\n\nCCS CDC (Virtual RS232) Example\r\n");

  #ifdef __PCH__
   printf("PCH: v");
   printf(__PCH__);
  #else
   printf("PCM: v");
   printf(__PCM__);
  #endif
   printf("\r\n");

   usb_init_cs();

  #if !(__USB_PIC_PERIF__)
   printf("USBN: 0x%X", usbn_get_version());
   printf("\r\n\n");
  #endif


   while (TRUE) {
      usb_task();
      usb_debug_task();

      if (kbhit()) {
         c=getc();
         if (c=='\n') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         if (c=='\r') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         else {usb_cdc_putc(c);}
      }
      if (usb_cdc_kbhit()) {
         c=usb_cdc_getc();
         if (c=='\n') {putc('\r'); putc('\n');}
         if (c=='\r') {putc('\r'); putc('\n');}
         else {putc(c);}
      }
   }
}


Must i install any driver or just program the pic ? i saw in the board that the rs232 virtual drivers the windows should auto install it.

If anyone could help me it should be great

Thx BoSS
K-BoSS



Joined: 03 Sep 2007
Posts: 6

View user's profile Send private message

PostPosted: Mon Sep 03, 2007 2:05 pm     Reply with quote

Forgot to say i am trying it with a 4mhz and a 20mhz clock both didn´t work :(
Ttelmah
Guest







PostPosted: Mon Sep 03, 2007 4:06 pm     Reply with quote

If the chip is powered, programmed, and correctly connected to the PC, you should get a window saying that 'new hardware has been found', and asking for the location of the .inf file.
You will only 'not' get this, if either the drivers have already been loaded (same device attached to the same port before), or there is something wrong with the connections to the PIC. Triple check the connections. Also the capacitance on the USB Vref pin.

Best Wishes
K-BoSS



Joined: 03 Sep 2007
Posts: 6

View user's profile Send private message

PostPosted: Tue Sep 04, 2007 2:34 am     Reply with quote

i was trying yesterday and i get the msg ... i try to install the cdc driver i download but it doesn´t work, my be i am trying the wrong driver, anyone knows where i can find the write one ?

thx for all
Ttelmah
Guest







PostPosted: Tue Sep 04, 2007 2:39 am     Reply with quote

Perhaps worth saying, there is no extra 'driver' as such. The chip uses the usbser.sys driver, which is included with the OS. All that is needed, is the .inf file, which tells the OS, to use this driver.
The files are in the 'drivers' directory, with the PIC code.
You want the one called cdc_NTXPVista.inf

Best Wishes
K-BoSS



Joined: 03 Sep 2007
Posts: 6

View user's profile Send private message

PostPosted: Tue Sep 04, 2007 2:28 pm     Reply with quote

this is the circuit that i am trying ... my windows is xp



Now i can make the windows reconize the pic but the driver doesn´t install correctly :(

Anyhelp would be great i am kind of newbie in this "usb" area .

thx all
Guest








PostPosted: Fri Sep 07, 2007 1:16 pm     Reply with quote

up! dosn´t anyone has any ideia ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 07, 2007 1:21 pm     Reply with quote

You don't have Vcc and GND connected to pins 11 and 12.
K-BoSS



Joined: 03 Sep 2007
Posts: 6

View user's profile Send private message

PostPosted: Sat Sep 08, 2007 9:35 am     Reply with quote

sorry the picture is not complete but its not the problem in the real circuit i connect both pins ... i think the problem is something related to the drivers...
K-BoSS



Joined: 03 Sep 2007
Posts: 6

View user's profile Send private message

PostPosted: Mon Sep 10, 2007 10:13 am     Reply with quote

if anyone has the circuit and the driver that could send to me ... i would be thankfull Very Happy
Steve H.
Guest







PostPosted: Mon Sep 10, 2007 2:29 pm     Reply with quote

These things can be tough - Windoze can be tough to get running with new hardware - especially when the hardware is new too!

I usually try to get a demo board - something that works so I have a known good starting point. Then I can mess around with the code, all the time knowing that there is nothing wrong with the hardware.

I know that sometimes the demo boards look expensive and we tend to not look at our cost per hour as engineers, but the demo board route has always saved me many hours in the past.

HTH - Steve H.
Ttelmah
Guest







PostPosted: Mon Sep 10, 2007 3:30 pm     Reply with quote

As one bit of added data to this, I had problems some time ago, with the PIC CDC drivers, hanging intermittently when used on some motherboards. It turned out they were all ones based on Via chipsets, and would not behave right, until you loaded the Via USB drivers, which are not meant to be needed with SP2 on XP. However without them, the behaviour was unreliable and unpredicatable. With them, it was fine.
I agree wholeheartedly, that you need to start from something like a working demo board. It was actually testing with just such a unit, and the basic 'example' files, that 'proved' the USB problem, was not with my hardware/software, and led me to looking at drivers...

Best Wishes
Guest








PostPosted: Mon Sep 10, 2007 6:43 pm     Reply with quote

forget about drivers untill the hardware works. the 470nf cap cannot be electrolitic must be ceramic or equ. download from microsoft UVCViewx86.exe this will tell you what is connected to the usb ports.
wwc



Joined: 27 Sep 2007
Posts: 2

View user's profile Send private message

PostPosted: Thu Sep 27, 2007 5:18 am     Reply with quote

hi, anyone have the file 18f4550.h ?
do you know where can download it ?
thanks.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Sep 27, 2007 5:25 am     Reply with quote

Should come with you CCS Compiler if not...

get it right there -->18f4550.h Wink
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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