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

Problem with usb connection (pic 18f2550)

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



Joined: 13 Oct 2010
Posts: 2

View user's profile Send private message

Problem with usb connection (pic 18f2550)
PostPosted: Wed Oct 13, 2010 6:53 pm     Reply with quote

Hi guys,

Here goes my problem.

I'm building a remote temperature meter. After 2 months I could finally get the RF mode operating, but now the USB module just doesn't works!!!

Simulating in Proteus the device connects normally but don't send or receive any information and when i try to see the VID and PID at the properties of the device in device manager, it just gives an error and freezes the screen needing a CTRL + ALT + DEL to reinitialize.

I used J1M's example for my base project, but changing the fuses because I need a 16MHz clock to my pic 18F (to RF comm can work normal) and a 48MHz to usb module.

I'm using a 16MHz crystal.

I'm wondering where my fuses can be wrong, cause I read several times the datasheet and articles and this just doesn't works!!

PLEASE HELP ME!!

My code: (Please don't look at the comments, I didn't have time to properly change them).
Code:

#include <18f2550.h>  //archivo de cabecera

#fuses   HSPLL,MCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL4,CPUDIV4,VREGEN,NOPBADEN // fuse con cristal 4Mhz

//#pragma _CONFIG1H = 0b00001110;
//#pragma _CONFIG1L = 0b00111011;

#use delay(clock=16000000)     // el clock que tendremos a la entrada del CPU

#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7,bits=8, ERRORS)//Configura serial
#include <stdlib.h>
#include <string.h>


/////////////////////////////////////////////////////////////////////////////
//
// CCS Library dynamic defines.  For dynamic configuration of the CCS Library
// for your application several defines need to be made.  See the comments
// at usb.h for more information
//
/////////////////////////////////////////////////////////////////////////////

#define USB_HID_DEVICE     FALSE             //deshabilitamos el uso de las directivas HID
#define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE    8                 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE    1                 //size to allocate for the rx endpoint 1 buffer


/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries.  See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////

#include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <PicUSB.h>         //Configuración del USB y los descriptores para este dispositivo
#include <usb.c>           //handles usb setup tokens and get descriptor reports

/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries.  See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////

#define LCD_DB4   PIN_B0
#define LCD_DB5   PIN_B1
#define LCD_DB6   PIN_B2
#define LCD_DB7   PIN_B3
//
#define LCD_RS    PIN_B5
//#define LCD_RW    PIN_B4
#define LCD_E     PIN_B6

#include <flex_lcd.c>

//*********************************************************

//*********************************************************
void main(void)
{
  char txt[18],saida[10],saida2[10],temp;
 
  unsigned char m,k;
  int x=0,j=0,i=0,test=0,u=0,sai=0;
  int8 recebe[1];
   usb_init();                      //inicializamos el USB

   usb_task();                      //habilita periferico usb e interrupciones
   usb_wait_for_enumeration();      //esperamos hasta que el PicUSB sea configurado por el host

    //disable_interrupts(global);   // desactivando interrupciones globales
    setup_adc_ports(NO_ANALOGS);  // desactivando puertos analogicos   
    set_tris_b(0x0);              // configurando los puertos como salidas

  Lcd_Init();  // Inicialização do LCD
  lcd_gotoxy(1,1);
  Lcd_putc("Temp.:"); //Escrita da palavra Temperatura na linha 1 e coluna 1
 
 // uart1_init(300); //Inicialização do módulo transmissão/recepção USART com baud rate de 300
  //delay_ms(90); //Atraso para estabilização do módulo
 // delay_ms(50);

while(1){
        //Leitura dos valores recebidos pela comunicação serial

       //if (kbhit()) {
//       while(m!= 'F' && k!='F' && sai!=1){
//         k=getc();
//         delay_ms(30);
//          m= getc();
//         delay_ms(30);
//         lcd_gotoxy(1,2);
//          Lcd_putc(k);
//          lcd_gotoxy(2,2);
//          Lcd_putc(m);
//        }
         sai=1;
        //}
         
        // delay_ms(20);
       
//////////////////////inicio da recepcao dos dados do pic Slave////////////////
//
//
//
///////////////////////////////////////////////////////////////////////////////
        if (kbhit()) { //se está chegando dados
         k=getc();  //lê o dado até o caracter
         
         txt[i]=k;
         i++;
         
         ////////////////////////teste de redundancia///////////////////////////
         //
         //descricao
         //
         ///////////////////////////////////////////////////////////////////////
         
           if(i==5){//inicio do teste de redundancia
           
           for(j=0;j<5;j++){
            temp=txt[j];
              for(x=0;x<4;x++){    //verifica se entre as cinco
                                   //char que chegaram pelo menos
                if(x!=j){          //duas tem que ser iguais
               
                    if(temp==txt[x]){test++;}
                   

                    if (test==2){
                     saida[u]=temp;
                     
                    //quando acha a igualdade salva na var saida
                     i=0;test=0;
                     }
                       //nao encontrando a igualdade repete-se o processo
                    if(x==4 && test<2){test=0;}
                }
              }
            }
             u++;

           }
         /////////////////////////Fim do teste de redundancia//////////////////
         //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

         //////////////////////////impressao lcd///////////////////////////////
         //
         //
         //////////////////////////////////////////////////////////////////////

          if(u==8 && saida[0]=='F'){ //Se a palavra inteira foi lida
            u=0;
         
          lcd_gotoxy(8,1);
           
          printf(lcd_putc,saida);//Apresenta temperatura no display LCD
          //lcd_gotoxy(1,14);
          //Lcd_putc(0xDF); //escreve º
          //Lcd_putc('C');// e escreve a palavra 'graus'
          sai=0;
         
          }//else{lcd_gotoxy(1,2);printf(lcd_putc,"não sincronizou");delay_ms(20);}
         ////////////////////////////////Fim da impressão lcd//////////////////
         //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//lembrar de testar a velocidade no modulo real
//pra saber quais as temporizações corretas para funcionar direito

 }//fim de recepção
 
////////////////////////////////Fim da recepção dos dados//////////////////////
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//////////////////////Início do envio dos dados para o PC//////////////////////
//
//
//
///////////////////////////////////////////////////////////////////////////////
 
 if(usb_enumerated())          //si el PicUSB está configurado
      {
      if (usb_kbhit(1))          //si el endpoint de salida contiene datos del host
         {
            usb_get_packet(1, recebe, 1); //cojemos el paquete de tamaño 1bytes del EP1 y almacenamos en recibe

            lcd_gotoxy(7,2);
               printf(lcd_putc,"haa");
            if (recebe == 0x61) // Modo_Suma
           {
               lcd_gotoxy(1,2);
               Lcd_putc("usb");
               usb_put_packet(1, saida, 8, USB_DTS_TOGGLE);
               sai=0;
           }
       
         }
         }

////////////////////////////////Fim do envio dos dados/////////////////////////
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
}
}


Thank you veeeery much if you help!! Crying or Very sad Crying or Very sad Question Question Question
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Oct 14, 2010 4:34 am     Reply with quote

Seriously, try a chip first.
Proteus has a _lot_ of problems with it's simulator, when you start getting into complex peripherals like the USB. As an example, of the last five USB projects I have built, only one worked in the Proteus 7 simulator, but all 5 work in the real chip...

Best Wishes
fabiooo



Joined: 13 Oct 2010
Posts: 2

View user's profile Send private message

PostPosted: Fri Oct 15, 2010 5:43 am     Reply with quote

thank you a lot Ttelmah,


I'm thinking about that this days, because if the Proteus run absolutely any configuration you build, he just can wrong at all, cause is too generic.

I'll try the real one and post the reply.
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