【iCore1S 双核心板_ARM】例程十五:USB_HID实验——双向数据传输

实验方法:

1、USB_HID协议免驱动,此例程不需要驱。

2、将跳线冒跳至USB_OTG,通过Micro USB 线将iCore1S USB-OTG接口与电脑相连。

3、打开上位机软件usb_hid.e,即可进行测试。

实验现象:

【iCore1S 双核心板_ARM】例程十五:USB_HID实验——双向数据传输

核心代码:

int main(void)
{ /* USER CODE BEGIN 1 */
int i;
unsigned char buffer[];
unsigned char send_buffer[];
static int counter;
RTC_DateTypeDef sDate;
RTC_TimeTypeDef sTime;
/* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init(); /* Configure the system clock */
SystemClock_Config(); /* Initialize all configured peripherals */
MX_GPIO_Init();
MX_RTC_Init();
MX_USB_DEVICE_Init();
SystemClock_Config(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */
/* USER CODE BEGIN WHILE */
while ()
{
/* USER CODE END WHILE */ /* USER CODE BEGIN 3 */
if(systick.second_flag == ){
systick.second_flag = ;
if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED){
if(counter ++ % ){
HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
memset(send_buffer,,);
sprintf((char *)send_buffer,"time:%02d:%02d:%02d %02d-%02d-%02d",sTime.Hours,sTime.Minutes,sTime.Seconds,sDate.Year,sDate.Month,sDate.Date);
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS,send_buffer,);
}else{
memset(send_buffer,,);
if(ARM_KEY_STATE == KEY_DOWN)
sprintf((char *)send_buffer,"key:KEY PRESS");
else
sprintf((char *)send_buffer,"key:");
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS,send_buffer,);
}
}
}
if(usb_receive_flag == ){
usb_receive_flag = ;
memcpy(buffer,usb_receive_buffer,usb_receive_counter);
memset(usb_receive_buffer,,usb_receive_counter);
for(i = ;i < ;i++){
buffer[i] = tolower(buffer[i]);
}
command_process(buffer);
}
}
/* USER CODE END 3 */ }

实验方法及指导书:

链接:http://pan.baidu.com/s/1kUWEs8R 密码:4m2r

【iCore1S 双核心板_ARM】例程十五:USB_HID实验——双向数据传输

上一篇:oracle之时间转换


下一篇:SharePoint 配置传出电子邮件设置