完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
使用的是M487开发板,把官网给的EMAC_TxRx例程烧录,然后接入网线到以太网接口,以太网旁边的灯是亮的,但过了一段时间以太网的灯灭了,ping IP也不成功,我连代码都没修改,刚开始也能获取到IP,这不懂是啥原因了,是代码问题还是以太网的接口有问题
void EMAC_TX_IRQHandler(void) { // Clean up Tx resource occupied by previous sent packet(s) EMAC_SendPktDone(); } /** * @brief EMAC Rx interrupt handler. * @param None * @return None */ void EMAC_RX_IRQHandler(void) { int i=0; while(1) { printf("u32PktLen =%drn",u32PktLen); // Check if there's any packets available if(EMAC_RecvPkt(auPkt, u32PktLen) == 0) break; // Process receive packet process_rx_packet(auPkt, u32PktLen); for(i=0;iMODE = ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk); /* Enable External XTAL (4~24 MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk); /* Waiting for 12MHz clock ready */ CLK_WaitClockReady( CLK_STATUS_HXTSTB_Msk); /* Switch HCLK clock source to HXT */ CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HXT,CLK_CLKDIV0_HCLK(1)); /* Set core clock as PLL_CLOCK from PLL */ CLK_SetCoreClock(FREQ_192MHZ); /* Set both PCLK0 and PCLK1 as HCLK/2 */ CLK->PCLKDIV = CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2; /* Enable IP clock */ CLK_EnableModuleClock(UART0_MODULE); CLK_EnableModuleClock(EMAC_MODULE); /* Select IP clock source */ CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HXT, CLK_CLKDIV0_UART0(1)); // Configure MDC clock rate to HCLK / (127 + 1) = 1.5 MHz if system is running at 192 MHz CLK_SetModuleClock(EMAC_MODULE, 0, CLK_CLKDIV3_EMAC(127)); /* Update System Core Clock */ /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */ SystemCoreClockUpdate(); /* Set GPB multi-function pins for UART0 RXD and TXD */ SYS->GPB_MFPH = ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk); SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD); // Configure RMII pins SYS->GPA_MFPL |= SYS_GPA_MFPL_PA6MFP_EMAC_RMII_RXERR | SYS_GPA_MFPL_PA7MFP_EMAC_RMII_CRSDV; SYS->GPC_MFPL |= SYS_GPC_MFPL_PC6MFP_EMAC_RMII_RXD1 | SYS_GPC_MFPL_PC7MFP_EMAC_RMII_RXD0; SYS->GPC_MFPH |= SYS_GPC_MFPH_PC8MFP_EMAC_RMII_REFCLK; SYS->GPE_MFPH |= SYS_GPE_MFPH_PE8MFP_EMAC_RMII_MDC | SYS_GPE_MFPH_PE9MFP_EMAC_RMII_MDIO | SYS_GPE_MFPH_PE10MFP_EMAC_RMII_TXD0 | SYS_GPE_MFPH_PE11MFP_EMAC_RMII_TXD1 | SYS_GPE_MFPH_PE12MFP_EMAC_RMII_TXEN; // Enable high slew rate on all RMII TX output pins PE->SLEWCTL = (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN10_Pos) | (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN11_Pos) | (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN12_Pos); /* Lock protected registers */ SYS_LockReg(); } // This sample application can response to ICMP ECHO packets (ping) // IP address is configure with DHCP, but if a lease cannot be acquired, a static IP will be used. int main(void) { SYS_Init(); UART_Open(UART0, 115200); Led_init(); key_init(); TIM_init(); // Select RMII interface by default EMAC_Open(g_au8MacAddr); // Init phy EMAC_PhyInit(); NVIC_EnableIRQ(EMAC_TX_IRQn); NVIC_EnableIRQ(EMAC_RX_IRQn); EMAC_ENABLE_RX(); EMAC_ENABLE_TX(); printf("emaec enable rx dfksa rn"); // if (dhcp_start() < 0) // { // // Cannot get a DHCP lease, use static IP. // printf("DHCP failed, use static IP 192.168.10.10n"); // g_au8IpAddr[0] = 0xC0; // g_au8IpAddr[1] = 0xA8; // g_au8IpAddr[2] = 0x0A; // g_au8IpAddr[3] = 0x0A; // } if (dhcp_start() > 0) { printf(" IP is %d.%d.%d.%dn",g_au8IpAddr[0],g_au8IpAddr[1],g_au8IpAddr[2],g_au8IpAddr[3]); } while(1); } |
|
相关推荐
1个回答
|
|
请检查下以太网的接口
|
|
|
|
只有小组成员才能发言,加入小组>>
664浏览 3评论
584浏览 2评论
393浏览 1评论
412浏览 1评论
375浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 04:24 , Processed in 0.483041 second(s), Total 48, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号