嗨,在我的项目基于CY7C68013A,我需要不时切换端点EP2的方向从外面到反之,反之亦然。我这样做是通过以下步骤:空隙TDyIIT(空)/在启动时调用{CUCUS= 0x10;//CKSPD[1:0]=10,对于48 MHz操作,禁用CKOUT SimCeldIn;//参见TRM部分15.14 IFCOFIGG= 0xCB;SYNCDELAY;//参见TRM部分15.14 ReVCTL= 0x03;SYNCDELAY;/参见TRM第15节14 / /端点FixPoT=0x80;FiPosie= 0x82. SimcTele:FippET= 0x84:SycCdTrime:FippET= 0x00;SycCdEnter;EP1OutCFG= 0xA0;SYNCDELAY;//参见TRM第15.14节EP1CIFFG=0xA0;SYNCDELAY;/ /参见TRM第15.14节EP2CFG= 0xA2;;//有效,OUT,BULD,512, 2×BuffSycCelp;EP4CFG= 0xA0;/OFF,OUT,BULD,512, 2×Buff同步延迟;EP6CFG= 0x00;/EP8CFG= 0x00;/OutpkDead=0x82};SycCdTrime:OutpkTurnay= 0x82. SycCdTrime;OutpkTurnay= 0x84:SycCdTrime;OutpkTurnay= 0x84. SycCurror;EP2FIFOCFG= 0x18;//AutoIn,自动输出,8位数据总线同步延迟;EP4FIFOCFG=0x00;//手动,8位数据总线同步延迟;/ /为所有EP定义总线宽度=8位(禁用)!)EP6FIFOFFG=0;/8位数据总线同步延迟;EP8FIFOFFG=0;/8位数据总线同步延迟;EP2BCL=0x80;/
ARM EP2OUT同步延迟;EP2BCL=0x80;SycCdEnter;EP4BCL=0x80;/ARM EP4OUT同步延迟;EP4BCL=0x80;SYNCDELAY;//标志PrPaGSABA= 0xC8;/FLAB - EP2满;FLAG-A E;用于EP2同步延迟的MPTY;pFrAgCsD=0x04;//FLAGD-PA7;FLAG-PRG。对于EP2同步延迟;FIFOP极性=0x00;SYNCDELAY;//端口D OED=0xFF;//可输出端口D(1输出,0输入)IOD=0x00;}在设备空闲时{无符号char TMP,重复空洞TDyPoLo(空隙)/重复调用;(EP2468 STAT和0x04){TMP=EP4FIFOOBUF〔0〕;OutpkTurn= 0x84;SycCdTrn;OutpkTalk=0x84;SycCdId;IOD= TMP;IF(TMP==0x01)//切换EP2到{SimcDelp;FiPosie= 0x80;SimcDelay;SimcDelay;EP2CFG= 0xE2;;//Healthin,in,Bulk,512, 2×Buff。同步延迟;FiPosit=0x80;FiPosie= 0x82. SycCdTrime:FippET= 0x00;SycCdTrn;IpkTalk=0x82. SimcDelp;IpkTalk=0x82. SycCdEnter;EP2FIFOFFG=0x18;//Au
tin,AutoOutin,8位数据总线同步延迟;EP2AutoLunh=0x02;SimcDelp;EP2AU;EP2AUToNeLnL= 0x00;Ep2BCH= 0x00;Ep2BCH=0x00;SycCdEnter;Ep2BCL=0;SycCdEnter;EP2BCL=0;SycCdEnter;} //切换EP2到输出{SycCdEnter;EP2CFG=0xA2;//OrthuleUndox,Bulk,512, 2×Buff同步延迟;SycRead;} },因此,我使用EP4(Bulk,OU)T,512x2,手动模式,8位)用于切换EP2(散装,OUT,512X2,自动模式,8位)的方向,同时改变PIN D0的状态以供外部设备使用。我的问题是:为什么在切换到完全标志之后总是变为低电平?
谢谢你的帮助维克托
以上来自于百度翻译
以下为原文
Hi,
In my project based on cy7c68013a I need from time to time to switch endpoint EP2 direction from OUT
to IN and vise versa.
I do it through the following steps:
void TD_Init(void) // Called once at startup
{
CPUCS = 0x10; // CLKSPD[1:0]=10, for 48MHz operation, disable CLKOUT
SYNCDELAY; // see TRM section 15.14
IFCONFIG=0xcb;
SYNCDELAY; // see TRM section 15.14
REVCTL=0x03;
SYNCDELAY; // see TRM section 15.14
//EndPoints
FIFORESET=0x80;
SYNCDELAY;
FIFORESET=0x82;
SYNCDELAY;
FIFORESET=0x84;
SYNCDELAY;
FIFORESET=0x00;
SYNCDELAY;
EP1OUTCFG = 0xA0;
SYNCDELAY; // see TRM section 15.14
EP1INCFG = 0xA0;
SYNCDELAY; // see TRM section 15.14
EP2CFG=0xa2; //valid, out, bulk, 512, 2 x buff
SYNCDELAY;
EP4CFG=0xa0; //valid, out, bulk, 512, 2 x buff
SYNCDELAY;
EP6CFG=0x00; //invalid
SYNCDELAY;
EP8CFG=0x00; //invalid
SYNCDELAY;
OUTPKTEND=0x82;
SYNCDELAY;
OUTPKTEND=0x82;
SYNCDELAY;
OUTPKTEND=0x84;
SYNCDELAY;
OUTPKTEND=0x84;
SYNCDELAY;
EP2FIFOCFG=0x18; //AUTOIN,AUTOOUT,8-bit data bus
SYNCDELAY;
EP4FIFOCFG=0x00; //manual, 8-bit data bus
SYNCDELAY;
//to define buswidth==8-bit for all EP (disabled too !!)
EP6FIFOCFG=0; //8-bit data bus
SYNCDELAY;
EP8FIFOCFG=0; //8-bit data bus
SYNCDELAY;
EP2BCL = 0x80; // arm EP2OUT
SYNCDELAY;
EP2BCL = 0x80;
SYNCDELAY;
EP4BCL = 0x80; // arm EP4OUT
SYNCDELAY;
EP4BCL = 0x80;
SYNCDELAY;
//Flags
PINFLAGSAB=0xc8; //FlagB - Full for EP2; FlagA - Empty for EP2
SYNCDELAY;
PINFLAGSCD=0x04; //FlagD - PA7 ; FlagC - Prg. for EP2
SYNCDELAY;
FIFOPINPOLAR=0x00;
SYNCDELAY;
//Port D
OED=0xff; //OutputEnable port D (1-output, 0-input)
IOD=0x00;
}
void TD_Poll(void) // Called repeatedly while the device is idle
{
unsigned char tmp;
if(!(EP2468STAT & 0x04))
{
tmp=EP4FIFOBUF[0];
SYNCDELAY;
OUTPKTEND=0x84;
SYNCDELAY;
OUTPKTEND=0x84;
SYNCDELAY;
IOD=tmp;
if(tmp==0x01) //switch EP2 to IN
{
SYNCDELAY;
FIFORESET=0x80;
SYNCDELAY;
SYNCDELAY;
EP2CFG=0xe2; //valid, in, bulk, 512, 2 x buff
SYNCDELAY;
FIFORESET=0x80;
SYNCDELAY;
FIFORESET=0x82;
SYNCDELAY;
FIFORESET=0x00;
SYNCDELAY;
INPKTEND=0x82;
SYNCDELAY;
INPKTEND=0x82;
SYNCDELAY;
EP2FIFOCFG=0x18; //AUTOIN,AUTOOUT,8-bit data bus
SYNCDELAY;
EP2AUTOINLENH=0x02;
SYNCDELAY;
EP2AUTOINLENL=0x00;
EP2BCH=0x00;
SYNCDELAY;
EP2BCH=0x00;
SYNCDELAY;
EP2BCL=0;
SYNCDELAY;
EP2BCL=0;
SYNCDELAY;
}
else //switch EP2 to OUT
{
SYNCDELAY;
EP2CFG=0xa2; //valid, out, bulk, 512, 2 x buff
SYNCDELAY;
SYNCDELAY;
}
}
}
Thus, I use EP4 (BULK, OUT, 512x2, MANUAL MODE, 8-bit) for switching EP2 (BULK, OUT, 512x2, AUTO MODE, 8-bit) direction and at the same time for changing status of pin D0 for its use by external device.
My question: why after switching from OUT to IN the FULL FLAG always becomes active (low)?
Thank you for your help
Victor