Thông báo

Collapse
No announcement yet.

Cần giúp Pic18f4550 giao tiếp usb hid trên windown 10

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Cần giúp Pic18f4550 giao tiếp usb hid trên windown 10

    Chào các bạn, lâu rồi không đụng món này. Không biết trên dienvietnam có ai đã từng gặp lỗi như mình chưa. Số là có ứng dụng mình làm giao tiếp hid trên 18f4550 chạy trên win 7,xp Ok hết.
    Nay mới up lên win 10, thì cấm vào báo lỗi này mới đau chứ lay hoai mãi mà không biết sữa thế nào nên lên đây hỏi xin ý kiến các tiền bối.
    Lỗi: CODE 43
    Click image for larger version

Name:	Untitled.png
Views:	1687
Size:	54.2 KB
ID:	1663147

    Nghi ngờ là do File descriptor chưa hợp lệ mình dùng HIDterminal tool của mikro c soạn file descriptor cho thiết bị là usb, trình biên dùng của mikro C.
    Code:
    const unsigned int USB_VENDOR_ID = 0x1234;
    const unsigned int USB_PRODUCT_ID = 0x0001;
    const char USB_SELF_POWER = 0x80;            // Self powered 0xC0,  0x80 bus powered
    const char USB_MAX_POWER = 50;               // Bus power required in units of 2 mA
    const char HID_INPUT_REPORT_BYTES = 4;
    const char HID_OUTPUT_REPORT_BYTES = 4;
    const char USB_TRANSFER_TYPE = 0x03;         //0x03 Interrupt
    const char EP_IN_INTERVAL = 1;
    const char EP_OUT_INTERVAL = 1;
    
    const char USB_INTERRUPT = 1;
    const char USB_HID_EP = 1;
    const char USB_HID_RPT_SIZE = 33;
    
    enum USB_SETTINGS {
        USB_VENDOR_ID = 0x1234,
        USB_PRODUCT_ID = 0x0001,
        USB_SELF_POWER = 0x80,            // Self powered 0xC0,  0x80 bus powered
        USB_MAX_POWER = 50,               // Bus power required in units of 2 mA
        HID_INPUT_REPORT_BYTES = 4,
        HID_OUTPUT_REPORT_BYTES = 4,
        USB_TRANSFER_TYPE = 0x03,         //0x03 Interrupt
        EP_IN_INTERVAL = 1,
        EP_OUT_INTERVAL = 1,
    
        USB_INTERRUPT = 1,
        USB_HID_EP = 1,
        USB_HID_RPT_SIZE = 33,
    };
    /* Device Descriptor */
    const struct {
        char bLength;               // bLength         - Descriptor size in bytes (12h)
        char bDescriptorType;       // bDescriptorType - The constant DEVICE (01h)
        unsigned int bcdUSB;        // bcdUSB          - USB specification release number (BCD)
        char bDeviceClass;          // bDeviceClass    - Class Code
        char bDeviceSubClass;       // bDeviceSubClass - Subclass code
        char bDeviceProtocol;       // bDeviceProtocol - Protocol code
        char bMaxPacketSize0;       // bMaxPacketSize0 - Maximum packet size for endpoint 0
        unsigned int idVendor;      // idVendor        - Vendor ID
        unsigned int idProduct;     // idProduct       - Product ID
        unsigned int bcdDevice;     // bcdDevice       - Device release number (BCD)
        char iManufacturer;         // iManufacturer   - Index of string descriptor for the manufacturer
        char iProduct;              // iProduct        - Index of string descriptor for the product.
        char iSerialNumber;         // iSerialNumber   - Index of string descriptor for the serial number.
        char bNumConfigurations;    // bNumConfigurations - Number of possible configurations
    } device_dsc = {
          0x12,                   // bLength
          0x01,                   // bDescriptorType
          0x0200,                 // bcdUSB
          0x00,                   // bDeviceClass
          0x00,                   // bDeviceSubClass
          0x00,                   // bDeviceProtocol
          8,                      // bMaxPacketSize0
          USB_VENDOR_ID,          // idVendor
          USB_PRODUCT_ID,         // idProduct
          0x0001,                 // bcdDevice
          0x01,                   // iManufacturer
          0x02,                   // iProduct
          0x00,                   // iSerialNumber
          0x01                    // bNumConfigurations
      };
    
    /* Configuration 1 Descriptor */
    const char configDescriptor1[]= {
        // Configuration Descriptor
        0x09,                   // bLength             - Descriptor size in bytes
        0x02,                   // bDescriptorType     - The constant CONFIGURATION (02h)
        0x29,0x00,              // wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
        1,                      // bNumInterfaces      - Number of interfaces in the configuration
        1,                      // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
        0,                      // iConfiguration      - Index of string descriptor for the configuration
        USB_SELF_POWER,         // bmAttributes        - Self/bus power and remote wakeup settings
        USB_MAX_POWER,          // bMaxPower           - Bus power required in units of 2 mA
    
        // Interface Descriptor
        0x09,                   // bLength - Descriptor size in bytes (09h)
        0x04,                   // bDescriptorType - The constant Interface (04h)
        0,                      // bInterfaceNumber - Number identifying this interface
        0,                      // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
        2,                      // bNumEndpoint - Number of endpoints supported not counting endpoint zero
        0x03,                   // bInterfaceClass - Class code
        0,                      // bInterfaceSubclass - Subclass code
        0,                      // bInterfaceProtocol - Protocol code
        0,                      // iInterface - Interface string index
    
        // HID Class-Specific Descriptor
        0x09,                   // bLength - Descriptor size in bytes.
        0x21,                   // bDescriptorType - This descriptor's type: 21h to indicate the HID class.
        0x01,0x01,              // bcdHID - HID specification release number (BCD).
        0x00,                   // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h.
        1,                      // bNumDescriptors - Number of subordinate report and physical descriptors.
        0x22,                   // bDescriptorType - The type of a class-specific descriptor that follows
        USB_HID_RPT_SIZE,0x00,  // wDescriptorLength - Total length of the descriptor identified above.
    
        // Endpoint Descriptor
        0x07,                   // bLength - Descriptor size in bytes (07h)
        0x05,                   // bDescriptorType - The constant Endpoint (05h)
        USB_HID_EP | 0x80,      // bEndpointAddress - Endpoint number and direction
        USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information    
        0x40,0x00,              // wMaxPacketSize - Maximum packet size supported
        EP_IN_INTERVAL,         // bInterval - Service interval or NAK rate
    
        // Endpoint Descriptor
        0x07,                   // bLength - Descriptor size in bytes (07h)
        0x05,                   // bDescriptorType - The constant Endpoint (05h)
        USB_HID_EP,             // bEndpointAddress - Endpoint number and direction
        USB_TRANSFER_TYPE,      // bmAttributes - Transfer type and supplementary information
        0x40,0x00,              // wMaxPacketSize - Maximum packet size supported    
        EP_OUT_INTERVAL         // bInterval - Service interval or NAK rate
    };
    
    const struct {
      char report[USB_HID_RPT_SIZE];
    }hid_rpt_desc = {
         0x06, 0x00, 0xFF,       // Usage Page = 0xFF00 (Vendor Defined Page 1)
          0x09, 0x01,             // Usage (Vendor Usage 1)
          0xA1, 0x01,             // Collection (Application)
      // Input report
          0x19, 0x01,             // Usage Minimum
          0x29, 0x40,             // Usage Maximum
          0x15, 0x00,             // Logical Minimum (data bytes in the report may have minimum value = 0x00)
          0x26, 0xFF, 0x00,       // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
          0x75, 0x08,             // Report Size: 8-bit field size
          0x95, HID_INPUT_REPORT_BYTES,// Report Count
          0x81, 0x02,             // Input (Data, Array, Abs)
      // Output report
          0x19, 0x01,             // Usage Minimum
          0x29, 0x40,             // Usage Maximum
          0x75, 0x08,             // Report Size: 8-bit field size
          0x95, HID_OUTPUT_REPORT_BYTES,// Report Count
          0x91, 0x02,             // Output (Data, Array, Abs)
          0xC0                   // End Collection
      };
    
    //Language code string descriptor
    const struct {
      char bLength;
      char bDscType;
      unsigned int string[1];
      } strd1 = {
          4,
          0x03,
          {0x0409}
        };
    
    
    //Manufacturer string descriptor
    const struct{
      char bLength;
      char bDscType;
      unsigned int string[16];
      }strd2={
        34,           //sizeof this descriptor string
        0x03,
        {'M','i','k','r','o','e','l','e','k','t','r','o','n','i','k','a'}
      };
    
    //Product string descriptor
    const struct{
      char bLength;
      char bDscType;
      unsigned int string[15];
    }strd3={
        32,          //sizeof this descriptor string
        0x03,
        {'U','S','B',' ','H','I','D',' ','L','i','b','r','a','r','y'}
     };
    
    //Array of configuration descriptors
    const char* USB_config_dsc_ptr[1];
    
    //Array of string descriptors
    const char* USB_string_dsc_ptr[3];
    
    void USB_Init_Desc(){
      USB_config_dsc_ptr[0] = &configDescriptor1;
      USB_string_dsc_ptr[0] = (const char*)&strd1;
      USB_string_dsc_ptr[1] = (const char*)&strd2;
      USB_string_dsc_ptr[2] = (const char*)&strd3;
    }
    Cám ơn mọi người.

  • #2
    Nghe thấy bảo lỗi này có từ thời Win8 rồi mà. Lên Win10 chi cho cực thế này

    Comment


    • #3
      Nguyên văn bởi htc2k14 Xem bài viết
      Nghe thấy bảo lỗi này có từ thời Win8 rồi mà. Lên Win10 chi cho cực thế này
      Bạn có cách sữa không.

      Comment


      • #4
        Mình chưa lên và thử vs win 10 bao h nên ko biết thực hư thế nào. Bạn có thể thử vào win 10 với chế độ "Disable driver signature enforcement".
        Thấy mấy thớt ghi Vendor ID của Microchip là 0x04D8.
        Cái thớt này thì xài stack của Micro chip http://www.microchip.com/forums/m827702.aspx
        Còn thằng này xài Mikroe http://forum.mikroe.com/viewtopic.php?f=12&t=52857
        Ko kiểm tra chính xác được vì chưa lên win10.

        Comment


        • #5
          Nguyên văn bởi htc2k14 Xem bài viết
          Mình chưa lên và thử vs win 10 bao h nên ko biết thực hư thế nào. Bạn có thể thử vào win 10 với chế độ "Disable driver signature enforcement".
          Thấy mấy thớt ghi Vendor ID của Microchip là 0x04D8.
          Cái thớt này thì xài stack của Micro chip http://www.microchip.com/forums/m827702.aspx
          Còn thằng này xài Mikroe http://forum.mikroe.com/viewtopic.php?f=12&t=52857
          Ko kiểm tra chính xác được vì chưa lên win10.
          Để mình thử thanks.

          Comment


          • #6
            Vẫn chưa biết cách khắc phục lỗi này, ai có kinh nghiệm chỉ mình với.

            Comment


            • #7
              Bác nào có cách chữa giúp mình với.:-

              Comment


              • #8
                Hay không lẻ HID USB không thể chạy trên win 10 sao.

                Comment


                • #9
                  Ai đã từng gặp trường hợp tương tự chỉ mình với.

                  Comment


                  • #10
                    Chưa có điều kiện test nhưng thử viết với xc8 + mplapx + thư viện usb trong mla tải từ microchip xem.
                    MikroC nó ăn sẵn quá ngoài 4 câu lệnh Enable, Disable, Write, Read còn cái gì nữa đâu để mà can thiệp, xem xét?

                    Comment


                    • #11
                      Nguyên văn bởi duong_act Xem bài viết
                      Chưa có điều kiện test nhưng thử viết với xc8 + mplapx + thư viện usb trong mla tải từ microchip xem.
                      MikroC nó ăn sẵn quá ngoài 4 câu lệnh Enable, Disable, Write, Read còn cái gì nữa đâu để mà can thiệp, xem xét?
                      Cám ơn bác, em nghĩ chắc hẳn không phải do thư viện của mikro c đâu ah. Vì nghe đâu là do win10 họ sữa đổi thư viện ngoại vi nên mới thế. Mà em build một project khác làm mouse thì cấm vào nhận được vậy mới đau chứ. Hết biết thế nào luôn.

                      Comment


                      • #12
                        Cái chuyện thư viện chạy được ở chỗ này không chạy được ở chỗ kia là thường tình mà.

                        Comment

                        Về tác giả

                        Collapse

                        thientanvt Tìm hiểu thêm về thientanvt

                        Bài viết mới nhất

                        Collapse

                        • bqviet
                          Trả lời cho Đấu tắt điện cho máy tính bảng
                          bởi bqviet
                          Bqv cáo lỗi vì chưa đủ khả năng diễn giải để người đọc hiểu. Người làm kỹ thuật sâu đôi khi như thế đó. Về việc nạp pin không vào dù cell mới, khả năng cái mạch quản lý đó đã hỏng - cũng chính là nguyên nhân đám cell cũ hỏng từ đầu.
                          06-12-2025, 17:17
                        • nguyendinhvan
                          Trả lời cho Xin hỏi về mạch thu FM/AM trong catsette
                          bởi nguyendinhvan
                          Theo tôi, nó chỉ là cái Tuy- ê - nơ, hoặc là khối Trung Văn Tần, nó một phần trong cái Da đì ô thôi. Vì có thấy một chỗ có ba chân hàn, giiống như chân Cờ rít sờ tăng 455 ki nô hẹc. Còn khối Tuy ê nơ thì không nhìn thây cái Di ốt Va di cáp...
                          05-12-2025, 19:59
                        • afrendly
                          Trả lời cho Đấu tắt điện cho máy tính bảng
                          bởi afrendly
                          Có vẻ ngoài hiểu biết của mình rồi. Cuối cùng mình quyết định tìm mua 2 pin trên Shopee, giá 200K thay vào. Tuy nhận pin được 1%, sạc mãi không vào nhưng cũng mở được máy lên. Vậy cũng tạm. Cảm ơn bạn đã hỗ trợ nhé....
                          04-12-2025, 01:27
                        • nick22
                          Trả lời cho Máy điện châm ?
                          bởi nick22
                          Đúng như bạn nói, máy điện châm hiện nay trên thị trường đã khá đa dạng về mẫu mã, chức năng và giá thành.
                          01-12-2025, 13:23
                        Đang tải...
                        X