Why, the first bye of USB HID must be zero?

General discussion on mikroC PRO for ARM.
Post Reply
Author
Message
lglgang
Posts: 40
Joined: 03 May 2013 04:07

Why, the first bye of USB HID must be zero?

#1 Post by lglgang » 26 Nov 2020 09:33

When I use the python send usb hid data to the mcu(stm32v103ze).
the mcu can not receive any data but zero.

then I search so many keyword in bing.com.

and I find some suggestion is the first data must be zero.

Then I set the data to zero. and when the mcu receive the data is ok.

and when the mcu receive the correct data and the LED is flash.

Code: Select all

char cnt;
char kk;
char readbuff[64];
char writebuff[64];

sbit LED at GPIOE_ODE.B0;

unsigned long int i = 0;
void main(void){
GPIO_Digital_Output(&GPIOE_BASE, _GPIO_PINMASK_0);
  HID_Enable(&readbuff,&writebuff);

  while(1){
    USB_Polling_Proc();               // Call this routine periodically
    kk = HID_Read();
    if(kk != 0){
    if(readbuff[1] ==0x31}
    {
     LED=~LED;
    }
      for(cnt=0;cnt<64;cnt++)
        writebuff[cnt]=readbuff[cnt];
      HID_Write(&writebuff,64);
    }
  }
}

Code: Select all

import pywinusb.hid as hid
import time

def readData(data):
    print(data)
    
all_devices = hid.HidDeviceFilter(vendor_id = 0x2dbc).get_devices()
print(all_devices)
device=all_devices[0]
device.open()
xx=device.find_output_reports()
report=xx[0]
buffer=[0x31]*65
buffer[0]=0x00  #must be zero 0
buffer[1]=0x31
buffer[2]=0x31
buffer[3]=0x31
#report.set_raw_data(buffer)
for i in range(100):
    report.set_raw_data(buffer)
    report.send()
    time.sleep(0.1)
    device.set_raw_data_handler(readData)
device.close()
Attachments
yuanzi USB HID TEST.rar
(279.17 KiB) Downloaded 53 times

lglgang
Posts: 40
Joined: 03 May 2013 04:07

Re: Why, the first bye of USB HID must be zero?

#2 Post by lglgang » 26 Nov 2020 09:37

mcu(stm32v103ze). is mcu(stm32f103ze).

Post Reply

Return to “mikroC PRO for ARM General”