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 CCS Technical Support

HID USB question

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



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

HID USB question
PostPosted: Fri Apr 13, 2012 2:47 am     Reply with quote

Hi, I am trying to exchange data between PIC18F Starter kit and PC using USB.

Currently, I managed to write embedded code so that my windows 7 recognize the Starter Kit as valid HID USB device.

below is my code
Code:



#include <18F46J50.h>
#fuses NOWDT, NOXINST, NODEBUG, HSPLL, PLL3, NOCPUDIV
#use delay(clock = 48MHz)
#include <def_var.h>
#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
#include <initialize.h>

void main(void)
{
   int8 out_data[USB_CONFIG_HID_TX_SIZE];
   int8 in_data[USB_CONFIG_HID_RX_SIZE];
   int8 send_timer=0;
   int16 buffer16 = 0;
   
   
   setup_oscillator(OSC_PLL_ON);
   delay_ms(50);
   usb_init_cs();


   setup_adc_ports(sAN4);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(4);
   
   memset(in_data, 0x00, USB_CONFIG_HID_RX_SIZE);
   memset(out_data, 0x00, USB_CONFIG_HID_TX_SIZE);

   while (TRUE)
   {
      usb_task();//
      if (usb_enumerated())
      {
         if (usb_kbhit(1))
         {//information received from the host

          // out_data[0]=buffer16&&0xFF;
            //out_data[1]=buffer16>>8;
         out_data[0] = 4;
         out_data[1] = 5;
         out_data[2] = 6;
         out_data[3] = 7;
         //endpoint = 1, send out_data, length = 2 bytes, and toggle between DATA0 and DATA1
            usb_put_packet(1, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE);
 
         }
   //   buffer16 = read_adc(ADC_START_AND_READ);
      buffer16 = 1004;
      }
   }
}


I changed buffer size to 4 just for debugging purposes.(changed value of USB_CONFIG_HID_TX_SIZE to 4)

This StarterKit, when connected to the PC, The host program I wrote is able to detect it's connection and disconnection.

However, it is not able to exchange any data.

I can not upload my actual source code, but it is based on the example code provided by following link

http://www.waitingforfriday.com/index.php/Open_Source_Framework_for_USB_Generic_HID_devices_based_on_the_PIC18F_and_Windows

This, and most other visual studio source code I found doesn't care "endpoint" in any of their source code. But the embedded side from CCS example does care about the end point in their functions. I think the host program should care about end point too, but I can not find any other library or example code online.

Does anyone have example Host program (in visual Studio) that can work with ex_usb_hid.c demo??

Thank you for reading.
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