|
各位好
我用8051和CP2201做了个以太网接口 在CP2201物理层初始化过程中 不管有没有连接 INT1RD的值总为0X31 不知道问题出在什么地方 希望高手能指点下 初始化程序如下
unsigned char PHY_Init()
{
unsigned char temp_char;
unsigned char retval = 0;
//--------------------------------------------------------------------------
// Auto-Negotiation Synchronization (Section 15.2 of CP220x Datasheet)
//--------------------------------------------------------------------------
// Step 1: Disable the PHY
PHYCN = 0x00;
// Step 2: Enable the PHY with link integrity test and auto-negotiation
// turned off
// A. Disable the Transmitter Power Save Option and Configure Options
TXPWR = 0x80;
PHYCF = ( SMSQ | JABBER | ADPAUSE | AUTOPOL );
// B. Enable the Physical Layer
PHYCN = PHYEN;
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
// C. Wait for the physical layer to power up
// wait_ms(10);
// D. Enable the Transmitter and Receiver
PHYCN = ( PHYEN | PHYTXEN | PHYRXEN );
// Step 3: Poll the Wake-on-Lan Interrupt
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
// A. Clear Interrupt Flags
temp_char = INT1;
// B. Start a new timeout for 1.5 seconds
// reset_timeout(ONE_SECOND+ONE_SECOND/2);
// C. Check for a signal
// If no signal is deteced, wait 1.5s, then continue
// if(timeout_expired()){
// break;
// }
//--------------------------------------------------------------------------
// Physical Layer Initialization (Section 15.7 of CP220x Datasheet)
//--------------------------------------------------------------------------
// Step 1: Synchronization procedure implemented above
// Step 2: Disable the physical layer
PHYCN = 0x00;
// Step 3: Configure the desired physical layer options including
// auto-negotiation and link integrity
PHYCF = ( SMSQ | LINKINTG | JABBER | AUTONEG | ADPAUSE | AUTOPOL );
// Step 4: Enable the physcial layer
// A. Enable the Physical Layer
PHYCN = PHYEN;
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
// B. Wait for the physical layer to power up
// wait_ms(10);
// C. Enable the Transmitter and Receiver
// Auto-negotiation begins now
PHYCN = ( PHYEN | PHYTXEN | PHYRXEN );
// Step 5: Wait for auto-negotiation to complete
// Clear INT1 Interrupt Flags
temp_char = INT1;
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
// Delay1ms(200);
// Start a six second timeout
// reset_timeout(6*ONE_SECOND);
// Check for autonegotiation fail or complete flag
while(1){
// If Auto-Negotiation Completes/Fails, break
if(INT1RD & (ANCINT | ANFINT)){
printf ("\nINT0RD=%.2x \n",(unsigned int)INT0RD);
printf ("\nINT1RD=%.2x \n",(unsigned int)INT1RD);
printf ("\nINT1RD=%.2x \n",(unsigned int)INT1RD);
break;
}
}
// Mask out all bits except for auto negotiation bits
temp_char = INT1RD;
temp_char &= (ANCINT | ANFINT);
// Check if Auto-Negotiation has FAILED
if(temp_char & ANFINT){
// Auto-Negotiation has failed
retval = LINK_ERROR;
} else
// Check if Auto-Negotiation has PASSED
if(temp_char == ANCINT){
// Auto-Negotiation has passed
retval = 0;
// Enable Link LED and Activity LED
// IOPWR = 0x0C;
} else
// Timeout Occured.
{
// Timeout
retval = LINK_ERROR;
}
return retval;
}
|
|