|
|
View previous topic :: View next topic |
Author |
Message |
kozlio05
Joined: 28 May 2010 Posts: 3
|
USB HID problem with CCS example ... |
Posted: Fri May 28, 2010 7:14 am |
|
|
Hello,
I'm working with the example ex_usb_hid.c given by CCS for communication with HID device. I'm using PIC18F2550. This is the beginning of my source:
Code: |
#include <18F2550.h> // header file for the PIC18F2550
// includes built-in functions and constants
// for arguments/returns.
#FUSES HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN, NOXINST
#use delay(clock=48000000)
#include <pic18_usb.h> //Microchip PIC18Fxx5x hardware layer
#include <usb_desc_hid.h> //USB Configuration and Device descriptors
#include <usb.c> //handles usb setup tokens and get descriptor
I have not made any changes in the descriptor files. After <usb.h> is called which looks like this:
#IFNDEF __USB_PROTOTYPES__
#DEFINE __USB_PROTOTYPES__
//// CONFIGURATION ////////////////////////////////////////////////////////////
#ifndef USB_CON_SENSE_PIN
#define USB_CON_SENSE_PIN 0
#endif
#IFNDEF USB_HID_BOOT_PROTOCOL
#DEFINE USB_HID_BOOT_PROTOCOL FALSE
#ENDIF
#IFNDEF USB_HID_IDLE
#DEFINE USB_HID_IDLE FALSE
#ENDIF
//should the compiler add the extra HID handler code? Defaults to yes.
#IFNDEF USB_HID_DEVICE
#DEFINE USB_HID_DEVICE TRUE
#ENDIF
#IFNDEF USB_CDC_DEVICE
#DEFINE USB_CDC_DEVICE FALSE
#ENDIF
//set to false to opt for less RAM, true to opt for less ROM
#ifndef USB_OPT_FOR_ROM
#define USB_OPT_FOR_ROM TRUE
#endif
#IFNDEF USB_MAX_EP0_PACKET_LENGTH
#DEFINE USB_MAX_EP0_PACKET_LENGTH 8
#ENDIF
////// USER-LEVEL API /////////////////////////////////////////////////////////
/**************************************************************
/* usb_enumerated()
/*
/* Input: Global variable USB_Curr_Config
/* Returns: Returns a 1 if device is configured / enumerated,
/* Returns a 0 if device is un-configured / not enumerated.
/*
/* Summary: See API section of USB.H for more documentation.
/***************************************************************/
int1 usb_enumerated(void);
|
... and so on.
After the declaration of function int1 usb_enumerated(void) this mistake was shown: A #DEVICE required before this line. My apologies but my English is far from perfect. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri May 28, 2010 8:37 am |
|
|
How are you trying to compile this?.
From CCS, or from MPLAB?.
The fault you describe, is what you see if you try from MPLAB, and usb.c is included in the project source files. MPLAB tries to compile this "on it's own", resulting in the error you describe.
Best Wishes |
|
|
kozlio05
Joined: 28 May 2010 Posts: 3
|
|
Posted: Sat May 29, 2010 6:05 am |
|
|
I used MPLAB because i want to use pickit2 as debugger. Indeed, i tried with CCS compiler and there were no errors. Thanks for your help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat May 29, 2010 7:16 am |
|
|
You can make it work with MPLAB. The problem is basically that iif you define a .c file as part of the project, MPLAB, assumes it is meant to be compiled "on it's own". In your 'project', you only want your 'main' source file. If you right click on the other files, and remove them from the project, you'll find it'll then work.
Best Wishes |
|
|
kozlio05
Joined: 28 May 2010 Posts: 3
|
|
Posted: Sat May 29, 2010 9:41 am |
|
|
Yes, you were right, my project was compiled with MPLAB. But I have another problem - my device is not recognized by the PC. I know the problem is not in the hardware because when I try with another USB HID example written in mikroC everything works fine. This is my source:
Code: |
#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL2,CPUDIV2,VREGEN
#use delay(clock=48000000)
#include <pic18_usb.h> //Microchip PIC18Fxx5x 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
#use fast_io(A) // all other ports default to 'standard_io'
#use fast_io(B) // fast_io means the tris bits only change
#use fast_io(C) // when we explicitly set them.
#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte ADCON1 = 0xFC1
#byte INTCON2 = 0xFF1
#bit RS = PORTC.0
#bit RW = PORTC.1
#bit EN = PORTC.2
#bit BUSY = PORTB.4
#bit EXT_INT0 = PORTB.0
#bit INTEDG0 = INTCON2.6
int digit = 0, count = 0;
void delay()
{
int i,j;
for(i = 0; i < 100; i++);
}
void init_io()
{
SET_TRIS_A(0x00);
// set up PORTB so RB0 is an input for the switch SW1, RB1-RB7 are outputs
SET_TRIS_B(0x01); // RB0 0 = input
ADCON1 = 0b00001111; //AN0-AN12 digital I/O
// set up remaining ports to be all outputs
SET_TRIS_C(0x00);
}
void wait_lcd()
{
RS = 0; //command
RW = 1; //read
EN = 0;
PORTA = 0x0F;
PORTB = PORTB | 0b00011110;
EN = 1; //Send the command
SET_TRIS_B(0b00010000);
while (BUSY == 1); //check if LCD is still busy
SET_TRIS_B(0x00);
PORTB = PORTB & 0b00000001;
RW = 0; //Turn to write commands
}
void init_lcd()
{
EN = 1;
PORTA = 0x08; //Communicate with 8-bit data bus, 5x8 character font
PORTB = PORTB | 0b00000110;
EN = 0;
wait_lcd();
EN = 1;
PORTA = 0x0E; //turn LCD and cursor on
PORTB = PORTB & 0x01;
EN = 0;
wait_lcd();
}
void clear_lcd()
{
PORTA = 0x01;
EN = 1;
EN = 0;
wait_lcd();
}
void write_text()
{
EN = 1;
RS = 1;
PORTA = digit;
PORTB = PORTB | 0b00000110;
EN = 0;
wait_lcd();
}
#INT_EXT
EXT_isr()
{
int units, decs, flag = 0;
delay();
while(EXT_INT0);
clear_lcd();
count = count + 1;
if (count > 10)
flag = 1;
jump:
if (flag == 0)
{
digit = count;
write_text();
}
if (flag == 1)
{
decs = count / 10;
digit = decs;
write_text();
units = count % 10;
digit = units;
write_text();
}
}
void main(void)
{
int8 out_data[4];
int8 in_data[4];
int p = 0;
usb_init_cs();
init_io();
init_lcd();
clear_lcd();
clear_interrupt(INT_EXT);
ext_int_edge(0,L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while (TRUE)
{
if (p = usb_enumerated())
{
if (usb_kbhit(1))
{
usb_get_packet(1, in_data, 4);
}
delay_ms(1);
}
}
}
|
To the original example I have added communication with LCD and external interrupt on RB0. 8 MHz quartz is used. Can you tell me if my fuses are correct ? When I try with CPUDIV1 to provide 48 MHz for CPU clock my device is not working at all. With CPUDIV2 it is working without USB connection. If fuses are correct where can be the problem? I haven't made any changes in headers and descriptor file. The processor is 18F2550. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
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
|