完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
各位大神,我用的是STM32F407,先用CUBMX生成了一个HID设备,然后改成自定义的设备,现在是接收数据正常,发送数据不正常,发送用的是这个函数USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); 接收用的是这个函数USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8);
static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) { uint8_t i; USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; if((rxbuff2[0]==0xfe)&&(rxbuff2[1]==0xa1)) { for(i=0;i<8;i++) { rxbuff=rxbuff2; } txbuff2[0]=0xfc; txbuff2[1]=0xa1; txbuff2[2]=0xff; txbuff2[3]=0xff; txbuff2[4]=0xff; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0xff; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_RESET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x00)) { for(i=0;i<8;i++) { rxbuff[8+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x01; txbuff2[3]=0x00; txbuff2[4]=0x01; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x01)) { for(i=0;i<8;i++) { rxbuff[16+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x02; txbuff2[3]=0x00; txbuff2[4]=0x00; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_9, GPIO_PIN_SET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x02)) { for(i=0;i<8;i++) { rxbuff[24+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x03; txbuff2[3]=0x00; txbuff2[4]=0x02; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET); } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x03)) { for(i=0;i<8;i++) { rxbuff[32+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x04; txbuff2[3]=0x09; txbuff2[4]=0x0b; txbuff2[5]=0x03; txbuff2[6]=0x72; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x04)) { for(i=0;i<8;i++) { rxbuff[40+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x05; txbuff2[3]=0x00; txbuff2[4]=0x64; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } else if((rxbuff2[0]==0xfd)&&(rxbuff2[2]==0x05)) { for(i=0;i<8;i++) { rxbuff[48+i]=rxbuff2; } txbuff2[0]=0xfb; txbuff2[1]=0x00; txbuff2[2]=0x06; txbuff2[3]=0x00; txbuff2[4]=0x00; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0x17; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } else if((rxbuff2[0]==0xfe)&&(rxbuff2[1]==0xa0)) { txbuff2[0]=0xfc; txbuff2[1]=0xa0; txbuff2[2]=0xff; txbuff2[3]=0xff; txbuff2[4]=0xff; txbuff2[5]=0xff; txbuff2[6]=0xff; txbuff2[7]=0xff; if (pdev->dev_state == USBD_STATE_CONFIGURED ) { if(hhid->state == CUSTOM_HID_IDLE) { hhid->state = CUSTOM_HID_BUSY; USBD_LL_Transmit(pdev, 0x82, txbuff2, 8); } } } if (pdev->dev_state == USBD_STATE_CONFIGURED ) { while(hhid->state != CUSTOM_HID_IDLE); hhid->state = CUSTOM_HID_BUSY; USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8); } // USBD_LL_PrepareReceive(pdev,CUSTOM_HID_EPOUT_ADDR1,rxbuff2,8); // USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData; // // ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0], // hhid->Report_buf[1]); // // USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR , hhid->Report_buf, // USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); return USBD_OK; } 以上是处理过程 只发出一个? |
|
相关推荐
17个回答
|
|
现在已经解解决了,是应为FIFO没有配置好,因为我用了两个端口HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40); HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40); HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x40); |
|
|
|
自己顶一下
|
|
|
|
楼主检查一下,发送HID有没有错。
|
|
|
|
budong cun bang ding
|
|
|
|
你底层的那些东西怎么改的?
|
|
|
|
你底层的那些东西怎么改的?
|
|
|
|
没搞过,纯粹是来赚ST币的,虽然不多,日积月累嘛
|
|
|
|
首先我没有用过cubemx,但是我对你的有点疑问
先用CUBMX生成了一个HID设备,然后改成自定义的设备, 设备描述符 接口描述符 HID描述符 端点描述符之类都是cubemx给你生成的? |
|
|
|
唯安an 发表于 2019-3-15 11:57 不是,自己在基础上修改的 |
|
|
|
现在已经解解决了,是应为FIFO没有配置好,因为我用了两个端口HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40); HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x40); HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 2, 0x40); |
|
|
|
首先我没有用过cubemx,但是我对你的有点疑问
|
|
|
|
|
|
szchangjiang 发表于 2019-3-15 10:17 我现在在用F3做HID双向通信,接收有问题,怀疑还是报告描述符的问题,楼主有代码吗,贴上来 |
|
|
|
恭喜楼主解决了问题
|
|
|
|
|
|
|
|
先试试一下原工程是不是可以通讯成功呢
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1441 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1373 浏览 3 评论
3018 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1519 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1949 浏览 1 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-4 02:23 , Processed in 1.351791 second(s), Total 105, Slave 88 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号