| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Genilson 
 
 
 Joined: 06 Jan 2011
 Posts: 4
 
 
 
			    
 
 | 
			
				| USB with PIC18F2550 |  
				|  Posted: Thu Jan 06, 2011 4:25 am |   |  
				| 
 |  
				| Good morning my friends! I'm trying to connect a microcontroller to the USB port and control via software. I am using ccs and some projects done that I downloaded from the Internet, but Windows does not detect my circuit. I already used various configurations of fuses and have not had success. Just need to start turn on a light, someone please help me!
 I'm using pic18f2550.
 
 Genilson medeiros
 |  |  
		|  |  
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Jan 06, 2011 4:53 am |   |  
				| 
 |  
				| Start simple. Can you turn on an LED with the processor, and flash it. Does it flash at the rate expected?. If not, USB is never going to work..... Then triple check your connections. USB, is a high frequency bus, and is not 'forgiving' of long wires, high capacitances on the pins, etc. etc.. You really need to be using a PCB for the connection to the chip.
 
 Describe:
 Your oscillator - what crystal, how is the circuit built etc..
 Are you using the USB connection sense pin?. If not, have you turned this off in the software?.
 Support circuitry round the processor. How is the supply generated, MCLR connection etc..
 Compiler version number 4.xxx.
 
 Why have you downloaded projects from the internet?. CCS, includes a simple 'serial' test program. Start with this, not anything else.
 
 
 Best Wishes
 |  |  
		|  |  
		| Genilson 
 
 
 Joined: 06 Jan 2011
 Posts: 4
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Jan 06, 2011 6:42 pm |   |  
				| 
 |  
				| Good night friends 
 I'm using the Mc PIC18F2550.
 Crystal of 20Mhz.
 
  	  | Code: |  	  | #include <18F2550.h>
 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
 #use delay(clock=4800000)
 
 #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    1                 //size to allocate for the tx endpoint 1 buffer
 #define USB_EP1_RX_SIZE    3                 //size to allocate for the rx endpoint 1 buffer
 
 
 #include <pic18_usb.h>
 #include <PicUSB.h>
 #include <usb.c>
 
 #define LED_VERDE        PIN_B6
 #define LED_VERMELHO     PIN_B7
 #define LED_ON           output_high
 #define LED_OFF          output_low
 
 #define modo      recibe[0]
 #define param1    recibe[1]
 #define status    send[0]
 
 
 void main(void) {
 
 int8 recibe[3];                  //declaramos variables 8 bits
 int8 send[1];
 
 
 LED_OFF(LED_VERDE);
 LED_ON(LED_VERMELHO);             //Acendemos led vermelho
 
 
 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
 
 LED_OFF(LED_VERMELHO);
 LED_ON(LED_VERDE);                    //Acendemos led verde
 
 while (TRUE)
 {
 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, recibe, 4); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe
 //O 3 india a quantidade de param
 if (modo == 1) // Modo_Led
 {
 if (param1 == 0) {LED_OFF(LED_VERDE); LED_OFF(LED_VERMELHO);} //apagamos los leds
 if (param1 == 1) {LED_ON(LED_VERDE); LED_OFF(LED_VERMELHO);} //encendemos led verde
 if (param1 == 2) {LED_OFF(LED_VERDE); LED_ON(LED_VERMELHO);} //encendemos led vermelho
 if (param1 == 3) {LED_ON(LED_VERDE); LED_ON(LED_VERMELHO);} //encendemos led vermelho
 }
 
 if (modo == 2) //Modo envio do Status do PIC para PC
 {
 status=1;
 usb_put_packet(1, send, 1, USB_DTS_TOGGLE);
 }
 
 }
 }
 
 }
 }
 
 | 
 My windows doesn´t detect the pic18f2550.
 I need help!
 thanks
 |  |  
		|  |  
		| Genilson 
 
 
 Joined: 06 Jan 2011
 Posts: 4
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Jan 06, 2011 7:50 pm |   |  
				| 
 |  
				|  	  | Code: |  	  | #include <18F2550.h>
 #fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL5, CPUDIV1, VREGEN
 #use delay(clock=48000000)
 
 #include<usb_cdc.h>
 
 void main()
 {
 output_high(PIN_B7);
 delay_ms(1000);
 output_low(PIN_B7);
 usb_cdc_init();
 usb_init();
 
 
 for(;;)
 {
 usb_task();
 
 if(usb_enumerated())
 {
 printf(usb_cdc_putc, "Testando conexão! \n");
 delay_ms(100);
 }
 }
 }
 
 | 
 Put to on a clear and led to Ve only if the pic was working, and that occurred led worked but windows is still not detecting the device.
 
 The light worked, but if I put on after usb_cdc_init (); usb_init (); it does not work, then came to the conclusion that the problem is between these two commands. But what can it be? I'm using CCS believe that 4013 is the newest. Already this continuity in my USB cable and it is perfectly funioando, esto connecting the white wire (d-) to pin 15 and the green wire (d +) at pin 16.
 |  |  
		|  |  
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Jan 07, 2011 3:25 am |   |  
				| 
 |  
				| On the original post, you are telling the USB code that you are not a HID device, but not supplying any USB descriptor table for whatever you are trying to be.... It won't enumerate, and usb_init, will hang.
 
 The second example, is more possible. However 'worried' about your comment 'led to Ve'. Hopefully this has got a current limiting resistor?. Otherwise, it _will_ stop the PIC from running properly. I'd add 'NOXINST' to the fuses, should be the default, but better to be sure.
 
 The device is waiting for enumeration. Implies:
 1) Vusb is not working right - must have a 470nF capacitor on it.
 2) Overall supply is not properly regulated.
 3) Not running at the right speed - have you tested that one hundred one second flashes of an LED, does take one hundred seconds. If not, it won't work. USB requires the clock to be _accurate_ to a fraction of a percent to work.
 4) Wrong connections. Triple check the USB to PIC connections. Remember that most connector wiring diagrams, show the connections from below.
 
 Best Wishes
 |  |  
		|  |  
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Jan 07, 2011 11:10 am |   |  
				| 
 |  
				|  	  | Quote: |  	  | I'm using CCS believe that 4013 is the newest. | 
 This is a junk version.  But you know, you get what you pay for.
 |  |  
		|  |  
		| IceMetal 
 
 
 Joined: 20 Nov 2008
 Posts: 79
 Location: white Plains, NY
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Thu Jan 20, 2011 5:19 pm |   |  
				| 
 |  
				|  	  | Ttelmah wrote: |  	  | Start simple. Can you turn on an LED with the processor, and flash it. Does it flash at the rate expected?. If not, USB is never going to work..... Then triple check your connections. USB, is a high frequency bus, and is not 'forgiving' of long wires, high capacitances on the pins, etc. etc.. You really need to be using a PCB for the connection to the chip.
 
 Describe:
 Your oscillator - what crystal, how is the circuit built etc..
 Are you using the USB connection sense pin?. If not, have you turned this off in the software?.
 Support circuitry round the processor. How is the supply generated, MCLR connection etc..
 Compiler version number 4.xxx.
 
 Why have you downloaded projects from the internet?. CCS, includes a simple 'serial' test program. Start with this, not anything else.
 
 
 Best Wishes
 | 
 
 
 I'm having the same problem, where can I find this serial test program?
 |  |  
		|  |  
		| gmua 
 
 
 Joined: 07 Feb 2011
 Posts: 11
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Feb 08, 2011 9:45 am |   |  
				| 
 |  
				|  	  | IceMetal wrote: |  	  | I'm having the same problem, where can I find this serial test program?
 | 
 
 IceMetal, you can find this and other examples inside the PICC folder
 
 In my case is:
 
 C:\Archivos de programa\PICC\Examples\ex_usb_serial.c
 
 In your case it should be:
 
 C:\Program Files\PICC\Examples\ex_usb_serial.c
 
 I've been trying to make it work with no luck yet, so if you succeed please post your results.
 |  |  
		|  |  
		| tim_sid 
 
 
 Joined: 11 Apr 2014
 Posts: 16
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 18, 2014 2:05 am |   |  
				| 
 |  
				| Yes, 3 days ago I encountered the same issue while using this firmware and 20MHz crystal. The problem was solved when I replaced the crystal by 12MHz. 
 Well, I can successfully transfer my data over USB between PC and PIC18F2550, but the speed of communication is veryy slow, it takes 12 seconds to transmit a 1KB file from PC to PIC. anyone can plz help me.. I really need some help.
 |  |  
		|  |  
		| ezflyr 
 
 
 Joined: 25 Oct 2010
 Posts: 1019
 Location: Tewksbury, MA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 18, 2014 6:55 am |   |  
				| 
 |  
				| Hi, 
 It's not at all clear to me what 'this firmware' really means, so please post your current program. Also, simply changing the crystal without doing anything else, especially on a PIC like this, is probably not going to have the intended/expected result. Again, show us your code!
 
 John
 |  |  
		|  |  
		| tim_sid 
 
 
 Joined: 11 Apr 2014
 Posts: 16
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 18, 2014 7:06 am |   |  
				| 
 |  
				| I am following the application attached here: http://320volt.com/en/ccs-c-ile-pic18f2550-usb-led-uygulamalari/
 
 I have modified the main code to transmit the file
 
 
  	  | Code: |  	  | void main(void) { set_tris_a(0x00);
 int flag=0;
 int8 recibe[3];
 int8 recv[1];
 int8 envia[1];
 int8 count=0x00;
 LED_OFF(LEDV);
 LED_ON(LEDR);
 
 usb_init();
 
 usb_task();
 usb_wait_for_enumeration();
 configurado por el host
 
 LED_OFF(LEDR);
 LED_ON(LEDV);
 output_a(0x00);
 while (TRUE)
 {
 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, recv, 1);
 
 }
 }
 }
 }
 | 
 |  |  
		|  |  
		| tim_sid 
 
 
 Joined: 11 Apr 2014
 Posts: 16
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 18, 2014 7:22 am |   |  
				| 
 |  
				| one correction: the code above is just receiving the data transmitted from PC. |  |  
		|  |  
		| ezflyr 
 
 
 Joined: 25 Oct 2010
 Posts: 1019
 Location: Tewksbury, MA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 18, 2014 8:38 am |   |  
				| 
 |  
				| Hi, 
 It's really pointless for us to try to help you unless you can post a small, compilable test program that shows your problem. So many details matter, and the more we have to assume, the less likely we are to be able to help....
 
 John
 |  |  
		|  |  
		| tim_sid 
 
 
 Joined: 11 Apr 2014
 Posts: 16
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 18, 2014 10:10 am |   |  
				| 
 |  
				| Here is the code: 
 [/code] 	  | Code: |  	  | ///////////////////////////////////////////////////////////////////////// ////                            PicUSB.c                             ////
 ////                                                                 ////
 //// Este ejemplo muestra como desarrollar un sencillo dispositivo   ////
 //// USB con el PIC18F2550, aunque puede ser facilmente adaptado     ////
 //// para la serie 18Fxx5x. Se suministra el PicUSB.exe, así como    ////
 //// su código fuente para Visual C# 2005, podréis encontrar tb      ////
 //// los drivers para el dispositivo. No se suministra esquema de    ////
 //// conexión puesto que está pensado para ser usado en el GTP USB,  ////
 //// cualquiera de las tres versiones disponibles, si aun no teneis  ////
 //// el programador, podeis utilizar el esquema de ese proyecto.     ////
 ////                                                                 ////
 //// Cuando el dispositivo sea conectado al PC, saldrá el asistente  ////
 //// para la instalación del driver. Instala el suministrado junto   ////
 //// a este ejemplo, lo encontrareis dentro de la carpeta Driver.    ////
 //// Una vez instalado podreis usar el PicUSB.exe para encender o    ////
 //// apagar el led bicolor del GTP USB, y para realizar la suma de   ////
 //// dos números introducidos.                                       ////
 ////                                                                 ////
 //// Realizado con el compilador CCS PCWH 3.227                      ////
 ////                                                                 ////
 //// Por: Jaime Fernández-Caro Belmonte        hobbypic@hotmail.com  ////
 ////                                                                 ////
 //// http://www.hobbypic.com                                         ////
 /////////////////////////////////////////////////////////////////////////
 #include <18F2550.h>
 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL3,CPUDIV1,VREGEN
 #use delay(clock=48000000)
 
 
 /////////////////////////////////////////////////////////////////////////////
 //
 // 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    1                 //size to allocate for the tx endpoint 1 buffer
 #define USB_EP1_RX_SIZE    1                 //size to allocate for the rx endpoint 1 buffer
 
 
 /////////////////////////////////////////////////////////////////////////////
 //
 // 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)
 //
 /////////////////////////////////////////////////////////////////////////////
 //#define USB_CON_SENSE_PIN PIN_B2  //CCS 18F4550 development kit has optional conection sense pin
 
 /////////////////////////////////////////////////////////////////////////////
 //
 // 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
 
 
 /////////////////////////////////////////////////////////////////////////////
 //
 // Al conectar el PicUSB al PC encendemos el Led Rojo hasta que el dispositivo
 // halla sido configurado por el PC, en ese momento encederemos el Led Verde.
 // Esperaremos hasta que se reciba un paquete proveniente del PC. Comprobaremos
 // el primer byte del paquete recibido para comprobar si queremos entrar en el
 // modo Suma, donde se realizará una suma de dos operandos, que corresponderan
 // con los dos bytes restantes del paquete recibido; una vez realizada la suma
 // enviaremos el paquete con el resultado de vuelta al PC. Si entramos en el
 // modo Led comprobaremos el segundo byte del paquete recibido para comprobar
 // si deberemos apagar los leds, encender el verder o el rojo.
 //
 /////////////////////////////////////////////////////////////////////////////
 #define LEDV    PIN_B6
 #define LEDR    PIN_B7
 #define LED_ON  output_high
 #define LED_OFF output_low
 
 #define modo      recibe[0]
 #define param1    recibe[1]
 #define param2    recibe[2]
 #define resultado envia[0]
 
 
 void main(void) {
 set_tris_a(0x00);
 int flag=0;
 int8 recibe[3];                  //declaramos variables
 int8 recv[1];
 int8 envia[1];
 int8 count=0x00;
 LED_OFF(LEDV);                   //encendemos led rojo
 LED_ON(LEDR);
 
 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
 
 LED_OFF(LEDR);
 LED_ON(LEDV);                    //encendemos led verde
 output_a(0x00);
 while (TRUE)
 {
 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, recv, 1); //cojemos el paquete de tamaño 3bytes del EP1 y almacenamos en recibe
 //usb_gets(1,recv,1,0);
 /*code*/
 }
 }
 }
 }
 
 
 | 
 |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |