Bon j'envoie le code pour ceux qui pourraient m'aider car la je galère vraiment.
Mon problème est que je n'arrive pas à écrire dans l'EP1 et que je ne sais pas pourquoi...
Mes leds 2 et 3 sont bien allumées et la 4 est bien éteinte, donc le programme s'exécute bien...
#define ALLOCATE_EXTERN
#include "fx2.h"
#include "fx2regs.h"
#define NOP _asm \
nop; \
_endasm;
void init_fx2(void)
{
CPUCS = 0x10; // Sets CPU to 48MHz clock
EP1INCS = EP1INCS & (0xff - bmEPSTALL); // Resetting the STALL bit in case it was set so the USB-Host
EP1OUTCS = EP1OUTCS & (0xff - bmEPSTALL); // doesn't get an error message for trying to read
EP1OUTCFG = 0xA0; // EP1OUT is Valid and the transfert type is BULK
EP1INCFG = 0xA0; // EP1IN is Valid and the transfert type is BULK
EP1OUTBC = 0x40; // Writing to EP1OUTBC rearms for an out transfer
OEA = 0x07; // Define PA0,PA1 and PA2 like output
PA0 = 1; // switch on led2
PA1 = 0; // switch on led3
PA2 = 0; // switch off led4
}
void toggle_ep1buf(void)
{
char i, j; // Variables for saving EP1OUTBC and counting
i = 0; // Initializing i
j = EP1OUTBC; // Saving EP1OUTBC to j
while (i < j) // While still being beneath the actual data in
{
EP1INBUF[i] = EP1OUTBUF[(j - 1) - i];
// EP1OUTBUF, we move the data from i to maximum-i
i++; // so anything gets turned upside down. Data is
} // take from EP1OUTBUF and written to EP1INBUF
EP1INCS = EP1INCS & (0xff - bmEPSTALL);
// Reset STALL bits, just to be sure...
EP1OUTCS = EP1OUTCS & (0xff - bmEPSTALL);
EP1INBC = j; // Arm endpoint 1 for in and out transfers
EP1OUTBC = 0x40;
}
void main(void)
{
init_fx2(); // Call init_fx2
PA1 = (EP1OUTCS & 0x01); // STALL
PA2 = (EP1OUTCS & 0x02)>>2; // BUSY
while (1) // Forever do:
{
if ( EP1OUTBUF[1] == 1)
PA0 = 0;
if (!(EP1OUTCS & bmEPBUSY)) // Wait for EP1OUTBUF having data and
{
if (!(EP1INCS & bmEPBUSY)){
toggle_ep1buf();
}
// EP1INBUF to be read for there is nothing overwritten
} // If both Buffers are ready, call toggle_ep1buf
}
}
-----