Ressuscitando: USB Bulk: 4550 + CCS (Exemplo: Oscope)

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

Ressuscitando: USB Bulk: 4550 + CCS (Exemplo: Oscope)

Mensagempor r.dallagnol » 02 Nov 2011 05:35

Srs.

Já que não houve nenhuma manifestação quando este assunto foi inserido junto a um já existente, vou expor novamente, como novo tópico:

Estou tentando usar o exemplo OScope do CCS mas estou encontranto a seguine dificuldade:

O dispositivo não aceita o driver BulkUSBDemo.inf e permanece com "dispositivo desconhecido".

No XP, ele sequer apresenta a tela para pedir o driver e exibe como se VID/PID fossem 0x00.

Já no Seven, ele até apresenta aquela frase USB_DESC_STRING_TYPE, do usb_desc_scope.h (CCS BULK DEMO) mas também não aceita quando direcionado manualmente.

Tentei usar aquele "clean-up" da framework da uChip mas também não ajudou.

Verifiquei e os VID / PID batem, tanto no usb.c (uc) como no .inf (PC). Pode ser mais algum erro de descritores?

Poderia ser Configuração incorreta do oscilador e seus PLLs?


Segue o código alterado para meu hardware;
Código: Selecionar todos
#include <18F4550.h>
//~~~ 20MHZ OSCILLATOR CONFIGS ~~~//
  #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
  #use delay(clock=48000000)
#use rs232(baud=9600, xmit=pin_c6, rcv=pin_a4)


/////////////////////////////////////////////////////////////////////////////
//
// 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 usb.c
#include <usb_desc_scope.h>      //USB Configuration and Device descriptors for this UBS device
#include <usb.c>              //handles usb setup tokens and get descriptor reports


/////////////////////////////////////////////////////////////////////////////
//
// Configure the demonstration I/O
//
/////////////////////////////////////////////////////////////////////////////
#define LED1 PIN_D0
#define LED2 PIN_D1
#define LED3 PIN_D2
#define LED_ON(x) output_high(x)
#define LED_OFF(x) output_low(x)
#define BUTTON_PRESSED() !input(PIN_A4)
#define USB_CON_SENSE_PIN PIN_E2

/////////////////////////////////////////////////////////////////////////////
//
// usb_debug_task()
//
// When called periodically, displays debugging information over serial
// to display enumeration and connection states.  Also lights LED2 and LED3
// based upon enumeration and connection status.
//
/////////////////////////////////////////////////////////////////////////////
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_connected)
      LED_ON(LED2);
   else
      LED_OFF(LED2);

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

   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;
}

//We will send a 512byte message to the PC.  Since the packet size is 64, this
//will be accomplished by sending 8 64byte packets and 1 0byte packet.
#DEFINE OSCDEMO_MESSAGE_SIZE 512

//a sine table is saved to ROM to simulate adc readings
#define SINE_TABLE_SIZE 256
const char sine_table[SINE_TABLE_SIZE] =
{
   127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169,
   172, 175, 178, 181, 184, 186, 189, 192, 195, 197, 200, 202, 205, 207, 210,
   212, 214, 216, 219, 221, 223, 225, 227, 229, 230, 232, 234, 236, 237, 239,
   240, 241, 243, 244, 245, 246, 247, 248, 249, 250, 250, 251, 252, 252, 253,
   253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 252, 252, 251, 250, 250,
   249, 248, 247, 246, 245, 244, 242, 241, 240, 238, 237, 235, 234, 232, 230,
   228, 226, 224, 222, 220, 218, 216, 214, 211, 209, 207, 204, 202, 199, 197,
   194, 191, 189, 186, 183, 180, 178, 175, 172, 169, 166, 163, 160, 157, 154,
   151, 148, 145, 142, 138, 135, 132, 129, 127, 124, 121, 118, 114, 111, 108,
   105, 102, 99, 96, 93, 90, 87, 84, 81, 78, 75, 73, 70, 67, 64,
   62, 59, 56, 54, 51, 49, 46, 44, 42, 39, 37, 35, 33, 31, 29,
   27, 25, 23, 22, 20, 18, 17, 15, 14, 12, 11, 10, 9, 8, 7,
   6, 5, 4, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11, 12,
   13, 14, 16, 17, 19, 21, 22, 24, 26, 28, 30, 32, 34, 36, 38,
   41, 43, 45, 48, 50, 53, 55, 58, 60, 63, 66, 69, 71, 74, 77,
   80, 83, 86, 89, 92, 95, 98, 101, 104, 107, 110, 113, 116, 119, 122, 125
};

//oscope.exe will send us a message containg two bytes.  The first byte
//is the sample_rate, or time division between ticks.  The second byte is
//the threshold, or trigger point of the scope.
unsigned int8 rxdata[2];
#define sample_rate rxdata[1]
#define threshold rxdata[0]


/////////////////////////////////////////////////////////////////////////////
//
// read_simulated_adc()
//
// Simulates reading an adc by using the sine_table[] array.  Also will
// simulate reading at faster/slower rates by using the sample_rate
// to change the speed at which we index the sine_table[] array.
//
/////////////////////////////////////////////////////////////////////////////
int8 read_simulated_adc(void)
{
   static unsigned int8 index;
   int8 ret;
   
   ret = sine_table[index];
   index += sample_rate+1;
   
   return(ret);
}

/////////////////////////////////////////////////////////////////////////////
//
// usb_scope_task()
//
// Reads an ADC value, and once it raises above the threshold read and
// sample 512 bytes and then transmit those 512 readings to the PC.
//
/////////////////////////////////////////////////////////////////////////////
void usb_scope_task(void)
{
   unsigned int8 adc;
   static unsigned int8 last_adc;
   int8 message[OSCDEMO_MESSAGE_SIZE];
   unsigned int16 i;

   adc = read_simulated_adc();

   if ((adc >= threshold)&&(last_adc <= threshold))
   {
      message[0] = adc;
      for (i=1;i<OSCDEMO_MESSAGE_SIZE;i++)
      {
         message[i] = read_simulated_adc();
      }
      usb_puts(1, message, OSCDEMO_MESSAGE_SIZE, 50);
   }
   else
   {
      last_adc = adc;
   }
}

void main(void)
{
   int1 run = 0;
   
   printf("\r\n\nCCS USB Bulk Example");
   usb_init_cs();
   printf("\r\n\n");   
   
   LED_ON(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);
   
   while (TRUE)
   {
      usb_task();
      usb_debug_task();
   
      if(usb_enumerated())
      {
         if (run)
            usb_scope_task();
   
         if (usb_kbhit(1))
         {
            usb_get_packet(1,rxdata,2);
            printf("\r\n--> Received 2 bytes: Thresh=%U Delay=%U", threshold, sample_rate);
            run = 1;
         }
      }
   }
}
Rodrigo Dall Agnol
Projetista / Desenvolvedor
r.dallagnol
Bit
 
Mensagens: 15
Registrado em: 04 Abr 2007 11:13
Localização: Cascavel / Paraná / Brasil

Mensagempor vtrx » 02 Nov 2011 12:33

Supondo que seu Hardware esta ok;
Código: Selecionar todos
#include <18F4550.h>
//#fuses XTPLL,NOWDT,NOPROTECT,LVP,NODEBUG,USBDIV,PLL1,CPUDIV2,VREGEN
#fuses XTPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

#use rs232(baud=9600, xmit=pin_c6, rcv=pin_a4)
#DEFINE USB_HID_DEVICE FALSE
#include "pic18_usb.h"         //Microchip PIC18Fxx5x hardware layer for usb.c
#include "usb_desc_scope.h"      //USB Configuration and Device descriptors for this UBS device
#include "usb.c"              //handles usb setup tokens and get descriptor reports
/////////////////////////////////////////////
#define LED1 PIN_D0
#define LED2 PIN_D1
#define LED3 PIN_D2
#define LED_ON(x) output_high(x)
#define LED_OFF(x) output_low(x)
#define BUTTON_PRESSED() !input(PIN_A4)
#define USB_CON_SENSE_PIN PIN_E2
/////////////////////////////////////////////////////////////////////////////
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_connected)
      LED_ON(LED2);
   else
      LED_OFF(LED2);

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

   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;
}

//We will send a 512byte message to the PC.  Since the packet size is 64, this
//will be accomplished by sending 8 64byte packets and 1 0byte packet.
#DEFINE OSCDEMO_MESSAGE_SIZE 512

//a sine table is saved to ROM to simulate adc readings
#define SINE_TABLE_SIZE 256
const char sine_table[SINE_TABLE_SIZE] =
{
   127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169,
   172, 175, 178, 181, 184, 186, 189, 192, 195, 197, 200, 202, 205, 207, 210,
   212, 214, 216, 219, 221, 223, 225, 227, 229, 230, 232, 234, 236, 237, 239,
   240, 241, 243, 244, 245, 246, 247, 248, 249, 250, 250, 251, 252, 252, 253,
   253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 252, 252, 251, 250, 250,
   249, 248, 247, 246, 245, 244, 242, 241, 240, 238, 237, 235, 234, 232, 230,
   228, 226, 224, 222, 220, 218, 216, 214, 211, 209, 207, 204, 202, 199, 197,
   194, 191, 189, 186, 183, 180, 178, 175, 172, 169, 166, 163, 160, 157, 154,
   151, 148, 145, 142, 138, 135, 132, 129, 127, 124, 121, 118, 114, 111, 108,
   105, 102, 99, 96, 93, 90, 87, 84, 81, 78, 75, 73, 70, 67, 64,
   62, 59, 56, 54, 51, 49, 46, 44, 42, 39, 37, 35, 33, 31, 29,
   27, 25, 23, 22, 20, 18, 17, 15, 14, 12, 11, 10, 9, 8, 7,
   6, 5, 4, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11, 12,
   13, 14, 16, 17, 19, 21, 22, 24, 26, 28, 30, 32, 34, 36, 38,
   41, 43, 45, 48, 50, 53, 55, 58, 60, 63, 66, 69, 71, 74, 77,
   80, 83, 86, 89, 92, 95, 98, 101, 104, 107, 110, 113, 116, 119, 122, 125
};

//oscope.exe will send us a message containg two bytes.  The first byte
//is the sample_rate, or time division between ticks.  The second byte is
//the threshold, or trigger point of the scope.
unsigned int8 rxdata[2];
#define sample_rate rxdata[1]
#define threshold rxdata[0]


/////////////////////////////////////////////////////////////////////////////
//
// read_simulated_adc()
//
// Simulates reading an adc by using the sine_table[] array.  Also will
// simulate reading at faster/slower rates by using the sample_rate
// to change the speed at which we index the sine_table[] array.
//
/////////////////////////////////////////////////////////////////////////////
int8 read_simulated_adc(void)
{
   static unsigned int8 index;
   int8 ret;
   
   ret = sine_table[index];
   index += sample_rate+1;
   
   return(ret);
}

/////////////////////////////////////////////////////////////////////////////
//
// usb_scope_task()
//
// Reads an ADC value, and once it raises above the threshold read and
// sample 512 bytes and then transmit those 512 readings to the PC.
//
/////////////////////////////////////////////////////////////////////////////
void usb_scope_task(void)
{
   unsigned int8 adc;
   static unsigned int8 last_adc;
   int8 message[OSCDEMO_MESSAGE_SIZE];
   unsigned int16 i;

   adc = read_simulated_adc();

   if ((adc >= threshold)&&(last_adc <= threshold))
   {
      message[0] = adc;
      for (i=1;i<OSCDEMO_MESSAGE_SIZE;i++)
      {
         message[i] = read_simulated_adc();
      }
      usb_puts(1, message, OSCDEMO_MESSAGE_SIZE, 50);
   }
   else
   {
      last_adc = adc;
   }
}

void main(void)
{
   int1 run = 0;
   
   printf("\r\n\nCCS USB Bulk Example");
   usb_init_cs();
   printf("\r\n\n");   
   
   LED_ON(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);
   
   while (TRUE)
   {
      usb_task();
      usb_debug_task();
   
      if(usb_enumerated())
      {
         if (run)
            usb_scope_task();
   
         if (usb_kbhit(1))
         {
            usb_get_packet(1,rxdata,2);
            printf("\r\n--> Received 2 bytes: Thresh=%U Delay=%U", threshold, sample_rate);
            run = 1;
         }
      }
   }
}
Avatar do usuário
vtrx
Dword
 
Mensagens: 2239
Registrado em: 20 Abr 2008 21:01

Mensagempor marcelo campos » 02 Nov 2011 16:16

"dispositivo desconhecido" em USB é como "Driver não tem ou não serve o que está tentando usar";

Então das 2 uma:
1) O driver que está tentando usar está errado e, aí é válido mesmo ver / conferir o vid/pid
2) O firmware do PIC está se identificando com vid/pid que não bate com seu driver, porquê: não sei tem que ver aonde ele está passando errado isto (e porque estaria ??!!)

Outro erro bem comum é inverter o D+ / D- do USB, ou a pci estar com estas duas ligações bem ruins/longas aí ele da´ a msg "Disp. não foi reconhecido... um ... teve um mau funcionamento...";
às vezes pode ser o esquecimento de colocar aquele cap. p/ desacoplamento de VUsb de 1uF no pino 23 do PIC, se não me engano, ele também dá este erro.

Já pegamos aqui também lotes inteiros de cabos USB que ao conectar nos nossos davam o erro acima; medindo eles foi constatado que tinham resitência de mais de 3ohms por fio! em comprimento de nem 1,5 metros...só china mesmo.

Oscilador errado acho que até pode dar isto também, me parece que seu exemplo tem serial, se sim uma maneira fácil de saber se está OK é se o baud rate está o esperado. O config "Usb PLL" não afeta mas ele é fácil pois tem só 2 opções então você pode alterar por tentativa e erro pra conferir

No mais é isso aí, é só cercar que o erro aparece

qualquer novidade ou dado à mais poste aí

boa sorte

MArcelo Campos
marcelo campos
Word
 
Mensagens: 648
Registrado em: 08 Ago 2009 08:37


Voltar para PIC

Quem está online

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

cron

x