初学USB,请大家支持下!
采用
STM32Cube生成STM32F103VBT6的MDK程序,
使用如下库函数
USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer,20);
发送20个字节的数据,在USB抓到的数据可以看到,
分成5次发送了??? 难道不能一次发送完成 吗??
请大神帮忙解惑下!!!
看红 {MOD}部分即可
按键盘“a”键的数据明显是一次发送8个字节
代码如下:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"
#include "usb_device.h"
osThreadId defaultTaskHandle;
osThreadId RS485_1Handle;
uint8_t uart1_rx_buf[20];
uint8_t uart1_rx_len = 20;
uint8_t uart1_rx_flag = 0;
uint8_t sendbuffer[20]={0x02,0x30,0x31,0x01,0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x93,0x03};
/* Private func
tion prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
void StartDefaultTask(void const * argument);
void RS485_1Task(void const * argument);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
osThreadDef(RS485_1, RS485_1Task, osPriorityNormal, 0, 128);
RS485_1Handle = osThreadCreate(osThread(RS485_1), NULL);
osKernelStart();
while (1)
{
}
}
void RS485_1Task(void const * argument)
{
for(;;)
{
if(uart1_rx_flag)
{
HAL_GPIO_WritePin(DR1_GPIO_Port,DR1_Pin, GPIO_PIN_SET); //使能485_1发送
osDelay(100);
HAL_UART_Transmit_IT(&huart1, uart1_rx_buf, uart1_rx_len);
osDelay(100);
HAL_GPIO_WritePin(DR1_GPIO_Port,DR1_Pin, GPIO_PIN_RESET); //使能485_1接收
uart1_rx_flag = 0;
osDelay(100);
USBD_HID_SendReport(&hUsbDeviceFS,sendbuffer,20); //此处发送20字节数据到PC机
osDelay(100);
}
}
}
一周热门 更多>