Jump to content

USB_RAW have a problemT_T


daibangden

Recommended Posts

I use labview 8.5.1 to communicate with microcontroler (PIC 18F4550).I programmed PIC by MirkoC, use HID Library for USB communication.

I also use NI_VISA Driver wizard for USB on my PIC, and the labview had recognized it.

When i communcate Labview with PIC by USB_RAW, I can write data form Labview to PIC but can't read data from PIC to Labview.

Could u help me to solve the problem. Thanks all! I also use temple of Find example in labview usb raw but it still like it. T_T

It's the first time i post in forum so sorry how can insert image? maybe my E not good!

Thanks again!

This is the code C for microcontroler:

unsigned char Reader[64], Writer[64];void interrupt(){	 HID_InterruptProc();					 // Keep alive	 TMR0L		 = 100;					 // Re-load TMR0L	 INTCON.TMR0IF = 0;					   // Re-enable TMR0 interrupts}//=============================================================void main(){	 ADCON1		= 0;					   // Set inputs as analog, Ref=+5V	 ADCON2		= 0xA6;	 TRISA		 = 0xFF;					// Set PORT A as inputs	 INTCON		= 0;	 INTCON2	   = 0xF5;	 INTCON3	   = 0xC0;	 RCON.IPEN	 = 0;	 PIE1		  = 0;	 PIE2		  = 0;	 PIR1		  = 0;	 PIR2		  = 0;	 T0CON		 = 0x47;					// Prescaler = 256	 TMR0L		 = 100;					 // Timer count is 256-156 = 100	 INTCON.TMR0IE = 1;					   // Enable T0IE	 T0CON.TMR0ON  = 1;					   // Turn Timer 0 ON	 INTCON		= 0xE0;					// Enable interrupts	 Hid_Enable(&Reader, &Writer);	 Lcd_Config(&PORTD,7,5,6,1,2,3,4);		// SETUP CHO LCD	 Lcd_Cmd(LCD_CLEAR);					  // Clear display	 Lcd_Cmd(LCD_CURSOR_OFF);				 // Cursor off	 Lcd_Out(1,1,"WRITE DATA TO LABVIEW");//=============================================================	 while(1)	 {	 Writer[0] = 'A';	 Writer[1] = 'B';	 Writer[2] = 'C';	 Hid_Write(&Writer,3);	 }Hid_Disable();}

another code include form this program

#include "Definit.h"#include "VARs.h"unsigned char const HID_INPUT_REPORT_BYTES	  = 3;unsigned char const HID_OUTPUT_REPORT_BYTES	 = 3;unsigned char const HID_FEATURE_REPORT_BYTES	= 2;unsigned char const NUM_ENDPOINTS			   = 2;unsigned char const ConfigDescr_wTotalLength	= USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN);unsigned char const HID_ReportDesc_len		  = 47;unsigned char const Low_HID_ReportDesc_len	  = HID_ReportDesc_len;unsigned char const High_HID_ReportDesc_len	 = HID_ReportDesc_len >> 8;unsigned char const Low_HID_PACKET_SIZE		 = HID_PACKET_SIZE;unsigned char const High_HID_PACKET_SIZE		= HID_PACKET_SIZE >> 8;unsigned char const DescTables[USB_DEVICE_DESCRIPTOR_ALL_LEN*2] = {// Device Descriptor	USB_DEVICE_DESCRIPTOR_LEN, 0,		   // bLength			   - Length of Device descriptor (always 0x12)	USB_DEVICE_DESCRIPTOR_TYPE, 0,		  // bDescriptorType	   - 1 = DEVICE descriptor	0x00, 0,								// bcdUSB				- USB revision 2.00 (low byte)	0x02, 0,								//										   (high byte)	0x00, 0,								// bDeviceClass		  - Zero means each interface operates independently (class code in the interface descriptor)	0x00, 0,								// bDeviceSubClass	0x00, 0,								// bDeviceProtocol	EP0_PACKET_SIZE, 0,					 // bMaxPacketSize0	   - maximum size of a data packet for a control transfer over EP0	0x03, 0,								// idVendor			  - Vendor  ID (low byte)	0x17, 0,								//									(high byte)	0x84, 0,								// idProduct			 - Product ID (low byte)	0x19, 0,								//									(high byte)	0x01, 0,								// bcdDevice			 - ( low byte)	0x00, 0,								//						 (high byte)	0x01, 0,								// iManufacturer		 - String1	0x02, 0,								// iProduct			  - String2	0x00, 0,								// iSerialNumber		 - ( None )	0x01, 0,								// bNumConfigurations	- 1// Configuration Descriptor	USB_CONFIG_DESCRIPTOR_LEN, 0,		   // bLength			   - Length of Configuration descriptor (always 0x09)	USB_CONFIG_DESCRIPTOR_TYPE, 0,		  // bDescriptorType	   - 2 = CONFIGURATION descriptor	ConfigDescr_wTotalLength, 0,			// wTotalLength		  - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.	0x00, 0,								//						 ( high byte)	0x01, 0,								// bNumInterfaces		- Number of interfaces	0x01, 0,								// bConfigurationValue   - Configuration Value	0x00, 0,								// iConfiguration		- String Index for this configuration ( None )	0xA0, 0,								// bmAttributes		  - attributes - "Bus powered" and "Remote wakeup"	50, 0,								  // MaxPower			  - bus-powered draws 50*2 mA from the bus.// Interface Descriptor	USB_INTERF_DESCRIPTOR_LEN, 0,		   // bLength			   - Length of Interface descriptor (always 0x09)	USB_INTERFACE_DESCRIPTOR_TYPE, 0,	   // bDescriptorType	   - 4 = INTERFACE descriptor	0x00, 0,								// bInterfaceNumber	  - Number of interface, 0 based array	0x00, 0,								// bAlternateSetting	 - Alternate setting	NUM_ENDPOINTS, 0,					   // bNumEndPoints		 - Number of endpoints used in this interface	0x03, 0,								// bInterfaceClass	   - assigned by the USB	0x00, 0,								// bInterfaceSubClass	- Not A boot device	0x00, 0,								// bInterfaceProtocol	- none	0x00, 0,								// iInterface			- Index to string descriptor that describes this interface ( None )// HID Descriptor	USB_HID_DESCRIPTOR_LEN, 0,			  // bLength			   - Length of HID descriptor (always 0x09)	USB_HID_DESCRIPTOR_TYPE, 0,			 // bDescriptorType	   - 0x21 = HID descriptor	0x01, 0,								// HID class release number (1.01)	0x01, 0,	0x00, 0,								// Localized country code (none)	0x01, 0,								// # of HID class descriptor to follow (1)	0x22, 0,								// Report descriptor type (HID)	Low_HID_ReportDesc_len, 0,	High_HID_ReportDesc_len, 0,// EP1_RX Descriptor	USB_ENDP_DESCRIPTOR_LEN, 0,			 // bLength			   - length of descriptor (always 0x07)	USB_ENDPOINT_DESCRIPTOR_TYPE, 0,		// bDescriptorType	   - 5 = ENDPOINT descriptor	0x81, 0,								// bEndpointAddress	  - In, EP1	USB_ENDPOINT_TYPE_INTERRUPT, 0,		 // bmAttributes		  - Endpoint Type - Interrupt	Low_HID_PACKET_SIZE, 0,				 // wMaxPacketSize		- max packet size - low order byte	High_HID_PACKET_SIZE, 0,				//					   - max packet size - high order byte	1, 0,								  // bInterval			 - polling interval (1 ms)// EP1_TX Descriptor	USB_ENDP_DESCRIPTOR_LEN, 0,			 // bLength			   - length of descriptor (always 0x07)	USB_ENDPOINT_DESCRIPTOR_TYPE, 0,		// bDescriptorType	   - 5 = ENDPOINT descriptor	0x01, 0,								// bEndpointAddress	  - Out, EP1	USB_ENDPOINT_TYPE_INTERRUPT, 0,		 // bmAttributes		  - Endpoint Type - Interrupt	Low_HID_PACKET_SIZE, 0,				 // wMaxPacketSize		- max packet size - low order byte	High_HID_PACKET_SIZE, 0,				//					   - max packet size - high order byte	1, 0,								  // bInterval			 - polling interval (1 ms)// HID_Report Descriptor	0x06, 0,								// USAGE_PAGE (Vendor Defined)	0xA0, 0,	0xFF, 0,	0x09, 0,								// USAGE ID (Vendor Usage 1)	0x01, 0,	0xA1, 0,								// COLLECTION (Application)	0x01, 0,//  The Input report	0x09, 0,								// USAGE ID - Vendor defined	0x03, 0,	0x15, 0,								//   LOGICAL_MINIMUM (0)	0x00, 0,	0x26, 0,								//   LOGICAL_MAXIMUM (255)	0x00, 0,	0xFF, 0,	0x75, 0,								//   REPORT_SIZE (8)	0x08, 0,	0x95, 0,								//   REPORT_COUNT (2)	HID_INPUT_REPORT_BYTES, 0,	0x81, 0,								//   INPUT (Data,Var,Abs)	0x02, 0,//  The Output report	0x09, 0,								// USAGE ID - Vendor defined	0x04, 0,	0x15, 0,								//   LOGICAL_MINIMUM (0)	0x00, 0,	0x26, 0,								//   LOGICAL_MAXIMUM (255)	0x00, 0,	0xFF, 0,	0x75, 0,								//   REPORT_SIZE (8)	0x08, 0,	0x95, 0,								//   REPORT_COUNT (2)	HID_OUTPUT_REPORT_BYTES, 0,	0x91, 0,								//   OUTPUT (Data,Var,Abs)	0x02, 0,//  The Feature report	0x09, 0,								// USAGE ID - Vendor defined	0x05, 0,	0x15, 0,								//   LOGICAL_MINIMUM (0)	0x00, 0,	0x26, 0,								//   LOGICAL_MAXIMUM (255)	0x00, 0,	0xFF, 0,	0x75, 0,								//   REPORT_SIZE (8)	0x08, 0,	0x95, 0,								//   REPORT_COUNT (2)	HID_FEATURE_REPORT_BYTES, 0,	0xB1, 0,								//   FEATURE (Data,Var,Abs)	0x02, 0,//  End Collection	0xC0, 0								 // END_COLLECTION};//******************************************************************************unsigned char const LangIDDescr[8] = {0x04,0,USB_STRING_DESCRIPTOR_TYPE,0,	0x09, 0,								// LangID (0x0409) - Low	0x04, 0								 //				 - High};//******************************************************************************unsigned char const ManufacturerDescr[44] = {22,0,USB_STRING_DESCRIPTOR_TYPE,0,	'D', 0, 0, 0,	'U', 0, 0, 0,	'Y', 0, 0, 0,	'_', 0, 0, 0,	'N', 0, 0, 0,	'G', 0, 0, 0,	'U', 0, 0, 0,	'Y', 0, 0, 0,	'E', 0, 0, 0,	'N', 0, 0, 0 };unsigned char const ProductDescr[36] = {18,0,USB_STRING_DESCRIPTOR_TYPE,0,	'C', 0, 0, 0,	'A', 0, 0, 0,	'R', 0, 0, 0,	'D', 0, 0, 0,	'_', 0, 0, 0,	'U', 0, 0, 0,	'S', 0, 0, 0,	'B', 0, 0, 0 };unsigned char const StrUnknownDescr[4] = {2,0,USB_STRING_DESCRIPTOR_TYPE,0};void InitUSBdsc(){Byte_tmp_0[0] = NUM_ENDPOINTS;Byte_tmp_0[0] = ConfigDescr_wTotalLength;Byte_tmp_0[0] = HID_ReportDesc_len;Byte_tmp_0[0] = Low_HID_ReportDesc_len;Byte_tmp_0[0] = High_HID_ReportDesc_len;Byte_tmp_0[0] = Low_HID_PACKET_SIZE;Byte_tmp_0[0] = High_HID_PACKET_SIZE;DescTables;LangIDDescr;ManufacturerDescr;ProductDescr;StrUnknownDescr;}

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.