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 support@ccsinfo.com

PIC18F45K50 USB HID Test - Unknown Device Error

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



Joined: 18 Jun 2014
Posts: 5

View user's profile Send private message

PIC18F45K50 USB HID Test - Unknown Device Error
PostPosted: Wed Jun 18, 2014 10:19 am     Reply with quote

Hi guys,

I’m trying to get a USB HID port working on a custom PIC18F45K50 board, but when I plug the USB in it appears as “Unknown device” in Windows device manager.

A blinking led test confirms that the PIC is running at the expected rate, 48MHz for fast USB. I’m using the internal regulator of the 45K50, no external crystal, and I’m running MPLAB 8.92 & CCS 5.0. Serial communication is also working fine.

Hardware wise I’ve connected the first three USB pins directly to the PIC, D+, D- and GND. The 5V is used only for connection sense (not power) and is connected to both pin A4 and GND, each through 100k resistors. The PIC’s Vusb pin is grounded with a 220 nF conductor.

The code I’m using is as follows:

Code:
#include "18F45K50.h"
#fuses NOCPUDIV, PLLEN, PLL4X, HSH, PRIMARY, NOIESO, NOFCMEN // 12mhz crystal, 48mhz clock for pic and usb
#use delay(internal=48MHz)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=PC) // Hardware uart

// Include the CCS USB Libraries.
#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

#define USB_HID_DEVICE     TRUE // Tells the CCS PIC USB firmware to include HID handling code.
#define USB_EP1_TX_ENABLE  USB_ENABLE_INTERRUPT // Turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE  USB_ENABLE_INTERRUPT // Turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE    64  // Allocate 64 bytes in the hardware for transmission
#define USB_EP1_RX_SIZE    64  // Allocate 64 bytes in the hardware for reception
#define USB_CON_SENSE_PIN PIN_A4

void main(void)
{
  int8 out_data[65];
  int8 in_data[65];
  int16 send_timer=0;

  printf("USB test\r\n");

  enable_interrupts(INT_USB);
  usb_init_cs(); // Initialise USB   
 
  while(true)
  {
      usb_task(); // handles connects/disconnects
 
      if (usb_enumerated())
      {
         if (!send_timer)
         {
            send_timer=2500;

            out_data[0]='a';
            out_data[1]='b';
            if (usb_puts(1, out_data, 65, USB_DTS_TOGGLE))
               printf("<-- Sending 2 bytes: %c %c\r\n", out_data[0], out_data[1]);
         }
         if (usb_kbhit(1))
         {
            usb_gets(1, in_data, 65, USB_DTS_TOGGLE);
            printf("--> Received data: %c %c\r\n",in_data[0],in_data[1]);
         }
         send_timer--;
         delay_ms(1);
      }
    restart_wdt();
   }
}


Any help as to what I'm doing wrong would be greatly appreciated. Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 11:30 am     Reply with quote

Your clock setup is 'dubious' (read wrong....). You are saying in the clock statement, to use the _internal_ oscillator.
Just us 'CLOCK=48MHz' (which won't override the fuses), or 'CLOCK=48MHz, CRYSTAL=12MHz'.

Your changes to the defines:
Code:

#define USB_HID_DEVICE     TRUE // Tells the CCS PIC USB firmware to include HID handling code.
#define USB_EP1_TX_ENABLE  USB_ENABLE_INTERRUPT // Turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE  USB_ENABLE_INTERRUPT // Turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE    64  // Allocate 64 bytes in the hardware for transmission
#define USB_EP1_RX_SIZE    64  // Allocate 64 bytes in the hardware for reception
#define USB_CON_SENSE_PIN PIN_A4


_Must_ be loaded _before_ the USB code. It tests for values being defined and then uses your definitions to change the settings. 'Retrospective' changing won't result in the configuration being changed...
Mikzi



Joined: 18 Jun 2014
Posts: 5

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 11:53 am     Reply with quote

Thank you for pointing this out. I've now moved the #defines before the includes.

I also changed the delay from #use delay(internal=48MHz) to #use delay(CLOCK=48MHz). To get this to work I also added the #fuse INTRC, to explicitly use the internal rc oscillator.

The problem with the unknown device in Windows still persists unfortunately.
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