Hi,
Thank you for your reply. At the moment I can read back 0xffff0000, tomorrow I'll check the waveforms again!
I had to modify a littlebit, is this code correct?
eth_init is a funtion that i call when sw3 pressed. I need this to debug on scope.
#define SYSTEM_CLOCK 120000000
#define MII_MANAGEMENT_CLOCK_SPEED 2500000 // typ. 2.5MHz Speed
#define PHY_IDENTIFIER 0x00221560 // MICREL KSZ8081RNA identifier
#define PHY_MASK 0xfffffff0 // don't check the revision number
#define PHY_ADDRESS 0x00 // address of external PHY on board
#define PHY_REG_ID1 0x02 // PHY Identification Register 1
#define PHY_REG_ID2 0x03 // PHY Identification Register 2
static unsigned short fnMIIread(unsigned char _mpadr, unsigned char _mradr)
{
ENET_MMFR = ((2 << 28) | (_mpadr << 23) | (_mradr << 18));
while ((ENET_EIR & ENET_EIR_MII_MASK) == 0) {} // wait until the read has completed
ENET_EIR = ENET_EIR_MII_MASK; // reset the interrupt event
return (unsigned short)ENET_MMFR; // return the data read
}
void eth_init(void)
{
/*Ethernet clock en*/
asm( "NOP" );
unsigned short usData;
unsigned long ulPhyIdentifier;
SIM_SCGC2 |= SIM_SCGC2_ENET_MASK;//eth clock en
SIM_SCGC5|= SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTA_MASK;//portb es porta clock en
PORTB_PCR0 |= PORT_PCR_MUX(4) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
PORTB_PCR1 |= PORT_PCR_MUX(4);
/*PORTA ALT4*/
PORTA_PCR5 = PORT_PCR_MUX(4);//PTA5 ALT4 RMII0_RXER
PORTA_PCR12 = PORT_PCR_MUX(4);//PTA12 ALT4 RMII0_RXD1
PORTA_PCR13 = PORT_PCR_MUX(4);//PTA13 ALT4 RMII0_RXD0
PORTA_PCR14 = PORT_PCR_MUX(4);//PTA14 ALT4 RMII0_CRS_DV
PORTA_PCR15 = PORT_PCR_MUX(4);//PTA15 ALT4 RMII0_TXEN
PORTA_PCR16 = PORT_PCR_MUX(4);//PTA16 ALT4 RMII0_TXD0
PORTA_PCR17 = PORT_PCR_MUX(4);//PTA17 ALT4 RMII0_RXD1
MPU_CESR = 0;
ENET_ECR = ENET_ECR_RESET_MASK;
for( usData = 0; usData < 10; usData++ )
{
asm( "NOP" );
}
ENET_MSCR = (((SYSTEM_CLOCK/(2 * MII_MANAGEMENT_CLOCK_SPEED)) + 1) << 1); // generate the communication channel clock
ENET_ECR = ENET_ECR_ETHEREN_MASK;
ulPhyIdentifier = fnMIIread(PHY_ADDRESS, PHY_REG_ID1); // check that the PHY is working correctly by reading its identifier - part 1
ulPhyIdentifier <<= 16;
ulPhyIdentifier |= fnMIIread(PHY_ADDRESS, PHY_REG_ID2); // check that the PHY is working correctly by reading its identifier - part 2
asm("nop");
while(1);