USB 18F4550

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

USB 18F4550

Mensagempor sandrini » 30 Jun 2009 16:16

Caro amigos,

Preciso enviar uma string utilizando a USB do 18F4550 utilizando o compilador CCS, conforme abaixo.

Porém está enviando somente os 2 primeiros caracteres, ou seja, "Te"...

Alguém saberia me informar o que pode estar errado?

Desde já, agradeço a atenção....

Código: Selecionar todos
#include <18F4550.H>
#device ADC = 10
#use delay(clock = 48000000)
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL2,CPUDIV1,VREGEN

#include <stdlib.h>
#use fast_io(C)      //Direcionamento dos pinos será manual na PORTC
#use fast_io(D)      //Direcionamento dos pinos será manual na PORTD

//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE  TRUE

//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_TX_ENABLE  USB_ENABLE_INTERRUPT   //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE    8  //allocate 8 bytes in the hardware for transmission

//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_RX_ENABLE  USB_ENABLE_INTERRUPT   //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE    8  //allocate 8 bytes in the hardware for reception

#include "pic18_usb.h"   //Microchip 18Fxx5x hardware layer for usb.c

#include "usb_desc_hid.h"   //USB Configuration and Device descriptors for this UBS device
#include "usb.c"        //handles usb setup tokens and get descriptor reports



void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;

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

   if (new_enumerated)
      OUTPUT_HIGH(PIN_D7);
   else
      OUTPUT_LOW(PIN_D7);

   //if (new_connected && !last_connected)
      //printf("\r\n\nUSB connected, waiting for enumaration...");
   //if (!new_connected && last_connected)
      //printf("\r\n\nUSB disconnected, waiting for connection...");
   //if (new_enumerated && !last_enumerated)
      //printf("\r\n\nUSB enumerated by PC/HOST");
   //if (!new_enumerated && last_enumerated)
      //printf("\r\n\nUSB unenumerated by PC/HOST, waiting for enumeration...");

   last_connected=new_connected;
   last_enumerated=new_enumerated;
}


void main(void){     //programa principal 

   char out_data[20];
   int8 in_data[20];
   int1 usb_1=0;


   usb_init();


   while(true)                      //laço principal do programa
        {
        usb_task();
        usb_debug_task();
        if (usb_enumerated())
           {
           if (usb_1)
             {
             
              out_data[0] = 'T';
              out_data[1] = 'e';
              out_data[2] = 's';
              out_data[3] = 't';
              out_data[4] = 'e';
              usb_put_packet(1, out_data, 5, USB_DTS_TOGGLE);
             
              usb_1=0;
                 
             }
         if (usb_kbhit(1))
            {
             usb_gets(1,in_data,2,5);
             
             usb_1=1;
            }   
         }
        }     
}
sandrini
Nibble
 
Mensagens: 65
Registrado em: 12 Out 2006 10:16

Mensagempor sandrini » 02 Jul 2009 11:13

Resolvido... era um problema no arquivo usb_desc.h que precisava ser modificado para receber e enviar uma quantidade maior de bytes....

Código: Selecionar todos
const char USB_CLASS_SPECIFIC_DESC[] = {
      6, 0, 255,    // Usage Page = Vendor Defined
      9, 1,            // Usage = IO device
      0xa1, 1,       // Collection = Application
      0x19, 1,        // Usage minimum
      0x29, 8,        // Usage maximum

      0x15, 0x80,        // Logical minimum (-128)
      0x25, 0x7F,        // Logical maximum (127)

      0x75, 8,        // Report size = 8 (bits)
      0x95, 8,        // Report count = 16 bits (2 bytes) - antes era 2
      0x81, 2,        // Input (Data, Var, Abs)
      0x19, 1,        // Usage minimum
      0x29, 8,        // Usage maximum
      0x75, 8,        // Report size = 8 (bits)
      0x95, 8,        // Report count = 16 bits (2 bytes) - antes era 2
      0x91, 2,        // Output (Data, Var, Abs)
      0xc0            // End Collection
   };
sandrini
Nibble
 
Mensagens: 65
Registrado em: 12 Out 2006 10:16

Mensagempor fabim » 02 Jul 2009 12:06

0x75, 8, // Report size = 8 (bits)
QUANTOS BITS TEM CADA PALAVRA ?

0x95, 8, // Report count = (8 bytes)
SÃO QUANTAS PALAVRAS DE n BITS ?

sE FOSSE 64 TU COLOCARIA 0X95 ,,,,, 0X40....

Facim né..
Mano, ve só.
Sou responsável pelo que escrevo!!! E não pelo que você entende !!!
fabim
Dword
 
Mensagens: 5001
Registrado em: 16 Out 2006 10:18
Localização: aqui uái!!!?


Voltar para PIC

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x