|
|
View previous topic :: View next topic |
Author |
Message |
cile
Joined: 10 May 2009 Posts: 17
|
USB communication 18f4550 <-> PC |
Posted: Tue Aug 02, 2011 8:28 am |
|
|
Hello !
I created small test board with PIC 18f4550 for USB communication between PC and PIC. I made GUI on the PC side which's job is to communicate with PIC. I have tested USB CCS CDC driver & example, works fine. (GUI in Matlab, communication via UART)
Now, I want to communicate like HID device. There is GUI implemented in C# Visual Studio 2010 (included dll. files for handling with USB), and I have problems.
Here is the simple code for PIC:
Code: |
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#include <flex_lcd.c>
#define USB_CONFIG_HID_TX_SIZE 64
#define USB_CONFIG_HID_RX_SIZE 64
#define USB_CON_SENSE_PIN PIN_B3 // sense pin
#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
void main(void)
{
int8 in_data[64];
usb_init();
lcd_init();
lcd_putc('\f');
lcd_putc("USB test");
while (TRUE)
{
usb_task();
if (usb_enumerated())
{
if (usb_kbhit(1))
{
usb_get_packet(1, in_data, 64);
lcd_putc("Anything"); //just to test if the program go in the loop, message has to be displayed on the LCD
printf(lcd_putc,"%u"in_data);
}
}
}
} |
Problem is, that 'usb_kbhit(1)' is never true, LCD screen nothing shows so, input buffer is empty... or?!?
I'm sending from GUI data size of 64 bytes
Code: |
int bufferPointer;
Byte data = 0;
for (bufferPointer = 0; bufferPointer < 64; bufferPointer++)
{
// We send the numbers 0 to 63 to the device
outputBuffer[bufferPointer] = data;
data++;
}
|
For two days I can not solve this...
When I connect PIC to PC, PC recognizes HID device ("ready to use")...
I have no idea |
|
|
xxopiumxx
Joined: 01 Jul 2011 Posts: 20
|
|
Posted: Wed Sep 07, 2011 8:32 am |
|
|
Before anything, there is something missing on your header,
like this:
Code: |
#DEFINE USB_HID_DEVICE TRUE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_TX_SIZE 64
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_RX_SIZE 64
|
Otherwise the device will not know either you are working on hid, or non-hid.
Make sure that your device is perfectly configured while working through USB, because it is quite a tricky one. |
|
|
|
|
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
|