我在刚开始遇到这个问题的时候,上网搜了下,讲得都不是很清楚。不非是“重新初始化”、”重新初始化MAC“,但是都是在文字表面。下面直接上代码,附上的代码是自己测试通过的。
1、通过DP83848配置为link状态变化,相应管教会有电平变化(具体看手册),从而触发STM32外部中断,通知STM32网线状态。下面是配置PHY
/************************************************************
**配置DP83848芯片当网线状态变化时产生一个变化电平通知MCU。
*************************************************************/
uint32_t Eth_Link_PHYITConfig(uint16_t PHYAddress)
{
/* PHY registers */
uint32_t tmpreg = 0;
tmpreg = ETH_ReadPHYRegister(PHYAddress, 2);
tmpreg = ETH_ReadPHYRegister(PHYAddress, 3);
/* Read MICR register */
tmpreg = ETH_ReadPHYRegister(PHYAddress, PHY_MICR);
/* Enable output interrupt events to signal via the INT pin */
tmpreg |= (uint32_t)PHY_MICR_INT_EN | PHY_MICR_INT_OE;
if(!(ETH_WritePHYRegister(PHYAddress, PHY_MICR, tmpreg)))
{
/* Return ERROR in case of write timeout */
return ETH_ERROR;
}
/* Read MISR register */
tmpreg = ETH_ReadPHYRegister(PHYAddress, PHY_MISR);
/* Enable Interrupt on change of link status */
tmpreg |= (uint32_t)PHY_MISR_LINK_INT_EN;
if(!(ETH_WritePHYRegister(PHYAddress, PHY_MISR, tmpreg)))
{
/* Return ERROR in case of write timeout */
return ETH_ERROR;
}