|
用EP6作BULK IN, 代码如下:
void TD_Init(void) // Called once at startup
{
WORD i;
// set the CPU clock to 48MHz
CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;
// set the slave FIFO interface to 48MHz, PORTS mode
IFCONFIG |= 0x40;
gpio_Init();
// default: all endpoints have their VALID bit set
// default: TYPE1 = 1 and TYPE0 = 0 --> BULK
// default: EP2 and EP4 DIR bits are 0 (OUT direction)
// default: EP6 and EP8 DIR bits are 1 (IN direction)
// default: EP2, EP4, EP6, and EP8 are double buffered
// we are just using the default values, yes this is not necessary...
EP1OUTCFG = 0xA0;
EP1INCFG = 0xA0;
SYNCDELAY;
EP2CFG = 0xA2; //EP2 is DIR=OUT, TYPE=BULK, SIZE=512, BUF=2x
SYNCDELAY;
EP4CFG = 0xA2;
SYNCDELAY;
EP6CFG = 0xE2;
SYNCDELAY;
EP8CFG = 0xE2;
SYNCDELAY;
// out endpoints do not come up armed
// since the defaults are double buffered, we must write dummy byte counts twice
EP2BCL = 0x80; // arm EP2OUT by writing byte count w/skip.
SYNCDELAY;
EP2BCL = 0x80;
SYNCDELAY;
EP4BCL = 0x80; // arm EP4OUT by writing byte count w/skip.
SYNCDELAY;
EP4BCL = 0x80;
SYNCDELAY;
for (i=0;i<512;i++)
EP6FIFOBUF[i] = i+3;
SYNCDELAY; //
EP6BCH = 0x02;
SYNCDELAY; //
EP6BCL = 0x00;
for (i=0;i<512;i++)
EP6FIFOBUF[i] = i+4;
SYNCDELAY; //
EP6BCH = 0x02;
SYNCDELAY; //
EP6BCL = 0x00;
// enable dual autopointer feature
AUTOPTRSETUP |= 0x01;
}
void TD_Poll(void) // Called repeatedly while the device is idle
{
if((EP2468STAT & bmEP6EMPTY))
{
SYNCDELAY; //
EP6BCH = 0x02;
SYNCDELAY; //
EP6BCL = 0x00;
SYNCDELAY; //
EP6BCH = 0x02;
SYNCDELAY; //
EP6BCL = 0x00;
}
}
初始化时往EP6的两个buffer 里填充数据,当两个buffer空时重新arm,第一次IN的数据正确,第二次IN的数据为32行相同的F4, F5,....,03,请教问题出在哪了? |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|