|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
小弟最近调试arm lpc1758和dp83640的以太网通讯,怎么也调不通,用周立功的例程writephy(),rmii线上不出数,不知道什么原因,哪位大侠帮帮忙啊。。。下边是程序:
void EMAC_IoInit()
{
LPC_SC->PCONP|=1<<30; //给以太网上时钟
LPC_EMAC->PowerDown=0x0;
LPC_PINCON->PINSEL2= 0x50150105;
/* LPC_PINCON->PINSEL2 &=~(0xF|(0X3<<8)); //P1.0 P1.1 P1.4
LPC_PINCON->PINSEL2 |=(0x5|(0X1<<8)); //ENET_TXD0 ENET_TXD1 ENET_TX_EN
LPC_PINCON->PINSEL2 &=~(0x3F<<16); //P1.8 P1.9 P1.10
LPC_PINCON->PINSEL2 |=(0x15<<16); //ENET_CRS ENET_RXD0 ENET_RXD1
LPC_PINCON->PINSEL2 &=~((unsigned int)0xf<<28); //P1.14 P1.15
LPC_PINCON->PINSEL2 |=(0x5<<28); //ENET_RX_ER ENET_REF_CLK
*/
LPC_PINCON->PINSEL3 &=~( (unsigned int)0xF<<18) ; //P1.25 P1.26 普通GPIO
//ENET_MDIO ENET_MDC
LPC_PINCON->PINMODE2 &= ~(0xf|(0X3<<8)|(0X3F<<16)|((unsigned int)0XF<<28)); //使能上拉
LPC_PINCON->PINMODE3 &= ~(0xf<<18);
LPC_PINCON->PINMODE_OD1 &= ~(0x3|(0X1<<4)|(0X7<<8)|(0XF<<14)); //引脚正常模式
}
void PHY_Write (unsigned int PhyReg, unsigned int Value)
{
/* Write a data 'Value' to PHY register 'PhyReg'. */
unsigned int tout;
LPC_EMAC->MCMD = 0;
/* Hardware MII Management for LPC176x devices. */
LPC_EMAC->MADR = (DP83640_ADR<<8) | PhyReg;
LPC_EMAC->MWTD = Value;
/* Wait utill operation completed */
for (tout = 0; tout < MII_WR_TOUT; tout++)
{
if ((LPC_EMAC->MIND & MIND_BUSY) == 0)
{
break;
}
}
}
uint32_t PHY_Read (unsigned int PhyReg)
{
uint32_t tout,val;
LPC_EMAC->MADR = DP83640_ADR | PhyReg;
LPC_EMAC->MCMD = 0x1; //读一个寄存器
/* Wait until operation completed */
for (tout = 0; tout < MII_RD_TOUT; tout++)
{
if ((LPC_EMAC->MIND & MIND_BUSY) == 0)
{
break;
}
}
LPC_EMAC->MCMD = 0;
val = LPC_EMAC->MRDD;
return (val);
}
void EMAC_Init()
{
uint32_t a=0;
// uint8_t a[3]={0x56,0xaa,0x01}; uint32_t j=0;uint8_t i=0;
LPC_EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX |
MAC1_SIM_RES | MAC1_SOFT_RES;
while(1)
{
a=LPC_EMAC->MAC1;
if( (a&(0x1<<15)) != 1)
{
break;
}
}
LPC_EMAC->MAC1 = 0x0;
// UART_Send(1,&a[0],1);
// LPC_EMAC->Command |= 0x1<<3;
// UART_Send(1,&a[1],1);
LPC_EMAC->Command = 0x1<<9;
LPC_EMAC->MAC1 = MAC1_PASS_ALL |MAC1_REC_EN;
LPC_EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN |MAC2_FULL_DUP|MAC2_HUGE_FRM_EN;
LPC_EMAC->IPGT=0x15;
LPC_EMAC->IPGR=0x12|0xc<<8;
LPC_EMAC->SUPP = 0x1<<8;
LPC_EMAC->Command = ((0x3<<9) |(0x3<<6)|0x3 );
LPC_EMAC->IntClear = 0xffff;
}
uint8_t BufferPtr[6]={0xaa,0x55,0x1,0x2,0x3,0x4};
int main()
{
uint8_t a[2]={0x55,0xff};
uint32_t i,tout=0;
SystemInit ();
SystemClockUpdate ();
UART_IOInit();
UART_Init(1,9600);
EMAC_IoInit();
EMAC_Init();
while(1)
{
PHY_Write (0x0, 0x20);
UART_Send(1,&a[0],1);
for(i=0;i<9999;i++)
for(tout=0;tout<1000;tout++);
}
} |
|