|
Here are the relevant pieces of code I am using:
Initialization:
void main_init()
{
//debug pin
OED = 0x02;
P3_1 = 1;
REVCTL = 3;
IFCONFIG = 0x00;
SYNCDELAY();
// Only using endpoint 2, zero the valid bit on all others
EP1OUTCFG = EP1INCFG = EP4CFG = EP6CFG = EP8CFG = 0x00;
SYNCDELAY();
EP2FIFOCFG = 0x00;
SYNCDELAY();
printf("Initialization Done.\n");
}
This is called when host selects an interface:
BOOL handle_set_interface(BYTE ifc, BYTE alt_ifc)
{
interface = ifc;
alt = alt_ifc;
if (!alt) {
EP2CFG = 0;
} else {
// Valid Out ISO 1024 DoubleBuf
EP2CFG = (1 << 7) | (0 << 6) | (1 << 4) | (1 << 3) | (2 << 0);
SYNCDELAY();
// OUT endpoints do NOT come up armed
EP2BCL = 0x80; // arm first buffer by writing BC w/skip=1
SYNCDELAY();
EP2BCL = 0x80; // arm second buffer by writing BC w/skip=1
}
return TRUE;
}
This is called from main() endless loop, when there are no EP0 requests to service:
void main_loop()
{
if (alt) {
if(!(EP2468STAT & bmEP2EMPTY)) {
P3_1 ^= 1;
EP2BCL = 0x80;
}
}
}
With this code, EMPTY bit in EP2468STAT is always cleared, regardless of if any data is sent to EP2.
If I change EP2FIFOCFG to 0x10, EMPTY bit in EP2468STAT is always set, regardless of if any data is sent to EP2.
|