打印
[STM32F1]

USB包长的问题

[复制链接]
568|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
JY-DX-JY|  楼主 | 2015-11-28 12:04 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
USB, TE, se, TI, IO
我在学STM32的USB。用的自定义设备。
部分程序如下:
void CustomHID_Reset(void)
{
  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/

  /* Current Feature initialization */
  pInformation->Current_Feature = CustomHID_ConfigDescriptor[7];

  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_INTERRUPT);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPRxAddr(ENDP1, ENDP1_RXADDR);
SetEPTxCount(ENDP1, 2);
  SetEPRxCount(ENDP1, 2);
  SetEPRxStatus(ENDP1, EP_RX_VALID);
  SetEPTxStatus(ENDP1, EP_TX_NAK);

  bDeviceState = ATTACHED;

  /* Set this device to response on default address */
  SetDeviceAddress(0);
}

。。。。。。。。。。。。。
/******************** Descriptor of Custom HID endpoints ******************/
    /* 27 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

    0x81,          /* bEndpointAddress: Endpoint Address (IN) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x02,          /* wMaxPacketSize: 2 Bytes max */
    0x00,
    0x01,          /* bInterval: Polling Interval (32 ms) */
    /* 34 */
           
    0x07,        /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,        /* bDescriptorType: */
                        /*        Endpoint descriptor type */
    0x01,        /* bEndpointAddress: */
                        /*        Endpoint Address (OUT) */
    0x03,        /* bmAttributes: Interrupt endpoint */
    0x02,        /* wMaxPacketSize: 2 Bytes max  */
    0x00,
    0x01,        /* bInterval: Polling Interval (20 ms) */
    /* 41 */
  }

。。。。。。。。。。。。。。。。。。
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u8 Receive_Buffer[2];
u8 temp;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name  : EP1_OUT_Callback.
* Description    : EP1 OUT Callback Routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP1_OUT_Callback(void)
{
  BitAction Led_State;

  PMAToUserBufferCopy(Receive_Buffer, ENDP1_RXADDR, 2);
  temp=Receive_Buffer[1];

  SetEPRxStatus(ENDP1, EP_RX_VALID);
        if(temp!=0x55)
                GPIO_SetBits(GPIOC, GPIO_Pin_12 );
        else
                GPIO_ResetBits(GPIOC, GPIO_Pin_12 );


}

。。。。。。。。。。。。。。。。。。。
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
#define nReportCnt 2


/* Private variables ---------------------------------------------------------*/
unsigned long int TimeCount=0;

u8 Transi_Buffer[nReportCnt];
u8 USB_Receive标志寄存器;
u8 flag=0;
u8 i=0;
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay(vu32 nCount);

/* Private functions ---------------------------------------------------------*/
void USB_SendString(void)
{

                 Transi_Buffer[0] = 0x07;
                 for(i=1;i<nReportCnt;i++)
                //i++;
                        Transi_Buffer=i;
     UserToPMABufferCopy(Transi_Buffer, ENDP1_TXADDR, nReportCnt);

                 
    SetEPTxCount(ENDP1, nReportCnt);
    SetEPTxValid(ENDP1);
}

。。。。。。。。。。。。。。
USB_Init();
        //USB_SendString();
  while (1)
  {
                                if ( TimeCount >= 3000000 ) //收到后上位机的数据后,将1S发送一次数据给PC
         {
             USB_SendString();
             TimeCount = 0x00;
                                         
         }
                                 TimeCount++;
                                 
  }

用bus_hound监视截图如下:

沙发
JY-DX-JY|  楼主 | 2015-11-28 12:09 | 只看该作者
每次发送两个数据。
我想要每次发送三个数据的效果:修改程序如下:
void CustomHID_Reset(void)
{
  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/*the default Interface*/

  /* Current Feature initialization */
  pInformation->Current_Feature = CustomHID_ConfigDescriptor[7];

  SetBTABLE(BTABLE_ADDRESS);

  /* Initialize Endpoint 0 */
  SetEPType(ENDP0, EP_CONTROL);
  SetEPTxStatus(ENDP0, EP_TX_STALL);
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
  Clear_Status_Out(ENDP0);
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
  SetEPRxValid(ENDP0);

  /* Initialize Endpoint 1 */
  SetEPType(ENDP1, EP_INTERRUPT);
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
  SetEPRxAddr(ENDP1, ENDP1_RXADDR);
  SetEPTxCount(ENDP1, 3);
  SetEPRxCount(ENDP1, 2);
  SetEPRxStatus(ENDP1, EP_RX_VALID);
  SetEPTxStatus(ENDP1, EP_TX_NAK);

  bDeviceState = ATTACHED;

  /* Set this device to response on default address */
  SetDeviceAddress(0);
}

。。。。。。。。。。。。。
/* 27 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

    0x81,          /* bEndpointAddress: Endpoint Address (IN) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x03,          /* wMaxPacketSize: 2 Bytes max */
    0x00,
    0x01,          /* bInterval: Polling Interval (32 ms) */
    /* 34 */

#define nReportCnt 3


/* Private variables ---------------------------------------------------------*/
unsigned long int TimeCount=0;

u8 Transi_Buffer[nReportCnt];
u8 USB_Receive标志寄存器;
u8 flag=0;
u8 i=0;
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay(vu32 nCount);

/* Private functions ---------------------------------------------------------*/
void USB_SendString(void)
{

                 Transi_Buffer[0] = 0x07;
                 for(i=1;i<nReportCnt;i++)
                //i++;
                        Transi_Buffer=i;
     UserToPMABufferCopy(Transi_Buffer, ENDP1_TXADDR, nReportCnt);

                 
    SetEPTxCount(ENDP1, nReportCnt);
    SetEPTxValid(ENDP1);
}

用bus hound监视截图如下:


感觉乱掉了。请问高手,哪里改的不对?谢谢!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:晴天响霹雳,平地一声雷。

245

主题

3349

帖子

30

粉丝