lifethief
Joined: 06 Aug 2008 Posts: 1
|
Picdem (18f4550) USB HID Help |
Posted: Wed Aug 06, 2008 7:53 am |
|
|
I am having an issues using the CCS USB with the pic and demo board. We have a test oven that output UART character data. However the ovens output is continuous. I need to have the pic (w eeprom) log this data at set intervals. I'm trying to use HID. I can get the PC to send data of any amount (tried 2 to 40 bytes) to the Pic but can't get the Pic to return more than 3 byte to the PC. I need to get 100, 40 to 80 character string from the pic to PC. Any help or guidance would be appropriated.
mylog.h
Code: |
#include <18F4550.h>
//Set A/D converter to 8-bits
#device adc=8
//Setup main
#FUSES HSPLL
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES PLL5 //Divide By 5
#FUSES CPUDIV1 //System Clock by 1
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define __USB_PIC_PERIF__ 1
//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 64 //allocate 64 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 64 //allocate 3 bytes in the hardware for reception
#define USB_CON_SENSE_PIN PIN_A1
#include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
#include "my_desc_hid.h" //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports
|
my_desc_hid.h
Code: |
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, 800, // Usage maximum =8
0x15, 0x00, // Logical minimum (-128) 0x80
0x25, 0xFF, // Logical maximum (127) 0x7F
0x75, 8, // Report size = 8 (bits)
0x95, 64, // Report count = 16 bits (2 bytes)
0x81, 2, // Input (Data, Var, Abs)
0x19, 1, // Usage minimum
0x29, 8, // Usage maximum
0x75, 8, // Report size = 8 (bits)
0x95, 64, // Report count = 16 bits (2 bytes)
0x91, 2, // Output (Data, Var, Abs)
0xc0 // End Collection
};
|
main code
MAX_OUT = 80;
Code: |
WHILE (TRUE)
{
BlinkLED();
usb_task();
usb_debug_task();
IF (usb_enumerated())
{
IF(sendoutput == 1)
{
sendoutput = 0;
delay_ms(250); //kjhtlhl
usb_puts(1, out_data, MAX_OUT, 250);
}
IF (usb_kbhit(1))
{
usb_gets(1, in_data, MAX_IN, 250);
printf("Recived 0x%X\n",in_data[0]);
if(in_data[0] == 1)
{
sendoutput = 1;
}
else if(in_data[0] == 4)
{
write_eeprom(0, in_data[1]);
}
else
{
}
}
delay_ms(1);
}
}
|
at this point I just want to get this simple code working. Im using the USB HID Device Library on the PC (http://labs.mike-obrien.net/view.aspx?projectid=hidlibrary) and since I can write data to the pic and can read 3 byte I know it is the pic code. |
|