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()