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

18f4550 usb controller

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



Joined: 20 Jun 2010
Posts: 7

View user's profile Send private message

18f4550 usb controller
PostPosted: Mon Oct 11, 2010 5:18 am     Reply with quote

Dear all,

Very best wishes.

I am using pic 18f4550 controller for usb to serial conversion.

I am trying to connect the Pic 18f4550 using the sample ccs code ex_usb_serial.c to make a virtual rs232 connection.

I am using <usb_cdc.h>.

I am able to make virtual com port on pc using this driver.
But I have one problem, whenever I try to open this com port using any serial port monitor software I got error "com port could be not opened".

I used crystal of 24mhz. Is this crystal problem.???????????

I uninstall driver and again install it till I persist same problem.

My source code is
Code:

 #define USB_CON_SENSE_PIN PIN_B2
//#include <18F4550.h>
#use delay(clock=24000000)

#include <usb_cdc.h>     
#define LED2 PIN_D1
#define LED3 PIN_D2
#DEFINE BUTTON PIN_A4
#define LED_ON output_low
#define LED_OFF output_high
#DEFINE LED1  PIN_D0
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

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()
{
   int8 out_data[20];
   int8 in_data[2];
   int8 send_timer=0;
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   OUTPUT_LOW(PIN_D0);
   OUTPUT_LOW(PIN_D1);
    OUTPUT_LOW(PIN_D2);
 
  while(true)
  {
         usb_task();
         usb_debug_task();
         if(usb_enumerated()) {
         if(!send_timer)
         {
               out_data[0]=50;//read_adc();
               out_data[1]=25;//!input(BUTTON);
         }       
         if (usb_kbhit(1))
         {
               usb_get_packet(1, in_data, 2);
               printf("\r\n--> Received data: 0x%X 0x%X",in_data[0],in_data[1]);
               if (in_data[0]) {LED_ON(LED2);} else {LED_OFF(LED2);}
               if (in_data[1]) {LED_ON(LED3);} else {LED_OFF(LED3);}
         }
         send_timer--;
       
       } 
  }

}

After connecting
cdc_NTXPVista.inf, driver loaded successfully, till I am having problem.

After compiling the source file I am getting the warning like this

interrupt disabled during call to re entrancy::(usb_token_reset)
interrupt disabled during call to re entrancy::(usb_cdc_flush_out_buffer)
interrupt disabled during call to re entrancy::(usb_flush_out)

Is these warnings have any relation with my problem ????????
I am using ccs4.084 version.

Can anyone help me please please,

very very thanx in adavance.

Quote:

On device manager in my computer my it shows the usb to uart with
error usb device can not start code 10


regard,


Girish
Code:


Last edited by brahme.girish on Mon Oct 11, 2010 5:48 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Mon Oct 11, 2010 5:29 am     Reply with quote

We need to see your fuse settings.
24MHz, can be used fine, but to give 24MHz as the CPU frequency, and the correct USB frequency, you will need the oscillator fuses as:
HS, CPUDIV1, PLL6
Learn to use the code buttons, otherwise the code is basically almost unreadable....
You show huge lumps of code, that are never going to be reached as posted. What are the sections like 'if (new_enumerated), meant to do?.
You have the classic 'wizard' error for SETUP_SPI. Needs to have 'false', not 'SPI_SS_DISABLED'. The latter turns off the slave select in a slave system, not the port itself.
Use the original demo program, just change the fuses for your 24MHz crystal, and see if this works, _before_ trying to do your own code.

Best Wishes


Last edited by Ttelmah on Mon Oct 11, 2010 10:07 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Mon Oct 11, 2010 8:16 am     Reply with quote

And, on the warnings, no.
They are just 'warnings', not errors. They occur because a couple of the CCS setup routines, call subroutines that are also used in the interrupt code. As a result, to prevent the possibility of code being called 'inside itself' (which would happen if an interrupt occurred while the external code was calling the same code), which is not supported on the PIC because of it's lack of a data stack, the compiler ensures that this can't happen by disabling interrupts in the external routines calling the functions., and gives this warning. The warning is given about this, because if the external code was 'timing critical', it might be necessary to re-write the code to avoid this. In this case it isn't, and the warnings do not matter.

Best Wishes
brahme.girish



Joined: 20 Jun 2010
Posts: 7

View user's profile Send private message

PostPosted: Tue Oct 12, 2010 1:50 am     Reply with quote

Ttelmah wrote:
And, on the warnings, no.
They are just 'warnings', not errors. They occur because a couple of the CCS setup routines, call subroutines that are also used in the interrupt code. As a result, to prevent the possibility of code being called 'inside itself' (which would happen if an interrupt occurred while the external code was calling the same code), which is not supported on the PIC because of it's lack of a data stack, the compiler ensures that this can't happen by disabling interrupts in the external routines calling the functions., and gives this warning. The warning is given about this, because if the external code was 'timing critical', it might be necessary to re-write the code to avoid this. In this case it isn't, and the warnings do not matter.

Best Wishes

hi,

Thanx for suggesting such modification. I made all that changes, but still the problem is same. Rather I uninstall that driver from my computer. And now I am using the samle program for usb cdc. This time there is no indication after connecting pic to pc.

Please help me.
best wishes,
girish
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