打印

EZ-USB FX2控制传输要发两次命令

[复制链接]
1412|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
我写了三个自定义请求,其中两个SC_SetData和SC_ReadData可以执行,但是只有发送两次命令才能正确得到结果,而SC_ResetFIFO:则直接不能用,发命令时interface提示:
Vendor Request failed
A device attached to the system is not functioning.
不知道什么原因,求老师给点指导。
沙发
妖怪被师傅抓了|  楼主 | 2015-9-24 17:19 | 只看该作者
      case SC_SET_FEATURE:                  // *** Set Feature
         if(DR_SetFeature())
            switch(SETUPDAT[0])
            {
               case FT_DEVICE:            // Device
                  if(SETUPDAT[2] == 1)
                     Rwuen = TRUE;      // Enable Remote Wakeup
                  else if(SETUPDAT[2] == 2)
                     // Set Feature Test Mode.  The core handles this request.  However, it is
                     // necessary for the firmware to complete the handshake phase of the
                     // control transfer before the chip will enter test mode.  It is also
                     // necessary for FX2 to be physically disconnected (D+ and D-)
                     // from the host before it will enter test mode.
                     break;
                  else
                     EZUSB_STALL_EP0();   // Stall End Point 0
                  break;
               case FT_ENDPOINT:         // End Point
                  *(BYTE xdata *) epcs(SETUPDAT[4]) |= bmEPSTALL;
                  break;
               default:
                  EZUSB_STALL_EP0();      // Stall End Point 0
            }
         break;
//自定义请求的响应///////////////////////////////////////////////////////////////////////                                                                       
                                               
                        case SC_SetData:
                                                DR_SetData();
                                                break;
                        case SC_ReadData:
                                                DR_ReadData();
                                                break;                                       
                        case SC_ResetFIFO:                                        //自定义请求,复位FIFO
                                                DR_ResetFIFO();                                //自定义请求的处理函数
                                                break;       
                       
                       
                       
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                       
      default:                     // *** Invalid Command
         if(DR_VendorCmnd())
            EZUSB_STALL_EP0();            // Stall End Point 0
                                 
                                 
                                 
   }

   // Acknowledge handshake phase of device request
   EP0CS |= bmHSNAK;
}

使用特权

评论回复
板凳
妖怪被师傅抓了|  楼主 | 2015-9-24 17:20 | 只看该作者
#define SETUP_RESERVED_REQUEST         0x60        //Reserved or illegal request

//////////////////////////////////////////////////////////////////////////////
//自定义请求
#define SC_SetData         0xB1
#define SC_ReadData        0xB2
#define SC_ResetFIFO                         0xB3                //复位FIFO操作



//////////////////////////////////////////////////////////////////////////////////
#define SC_GET_STATUS         0x00   // Setup command: Get Status

使用特权

评论回复
地板
妖怪被师傅抓了|  楼主 | 2015-9-24 17:22 | 只看该作者
BOOL DR_SetData(void)
{               
               
        WORD DATA0;
        BYTE i;
//        EP0BCH=0;
//EP0BCL=2;
//        EZUSB_Delay(100);
                if(SETUPDAT[7]!=0||SETUPDAT[6]!=0)
                {
                        EP0BCH=SETUPDAT[7];
                        SYNCDELAY;
                        EP0BCL=SETUPDAT[6];
                        SYNCDELAY;
                        while(EP0CS&bmEPBUSY);
                }
               
                OEC=0XFF;
                DATA0=EP0BUF[0]*256+EP0BUF[1];       
                PC1=0;                                                                                                        //cs1
                EZUSB_Delay(20);                                                                //hold cs
                for (i=0;i<16;i++)
                {
                PC5=1;                                                                                                        //SCK        HIGH
                        if (DATA0&0x8000)                                                                       
                        PC6=1;                                                                                                        //DIN
                        else
                        PC6=0;
                EZUSB_Delay(20);                                                                //SETUP TIME
                PC5=0;                                                                                                        //SCK LOW                       
                EZUSB_Delay(20);                                                                //HOLD TIME
                DATA0<<=1;                                                                                //next bit
                }
                PC1=1;       
                     EP0CS|=bmHSNAK;
                return(FALSE);       
}

使用特权

评论回复
5
妖怪被师傅抓了|  楼主 | 2015-9-24 17:24 | 只看该作者
BOOL DR_ResetFIFO()                                                //用于复位FIFO
{
        if((SETUPDAT[2]==0x01) & (SETUPDAT[3]==0x01))        //wValue=0x0101,表示复位FIFO
        {
                SYNCDELAY;                    
                EP2CFG = 0xA0;                                        //4重buffer,每次512字节,Host->Device
                SYNCDELAY;                                       
                EP6CFG = 0xE0;                                        //4重buffer,每次512字节,Device->Host
……
……
}
        else if((SETUPDAT[2]==0x02) & (SETUPDAT[3]==0x02))       
        {       
testmode=TRUE;
        }
        else if((SETUPDAT[2]==0x03) & (SETUPDAT[3]==0x03))       
        {                                                                        //wValue=0x0303,表示关闭测试模式
                testmode=FALSE;
        }
        EP0CS |= bmHSNAK;                                        //握手
        return(FALSE);
}

使用特权

评论回复
6
妖怪被师傅抓了|  楼主 | 2015-9-24 17:29 | 只看该作者
我用EZ-USB Interface发送请求码0xB1值为cfff,总线没有正确响应,再发一遍请求码0xB1值为cfff,输出正确。我发送请求码0xB3,Value为0x0202,结果EZ-USB Interface提示:
Vendor Request failed
A device attached to the system is not functioning.

使用特权

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

本版积分规则

7

主题

32

帖子

1

粉丝