完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
最近正在看32以太网通信的问题,用的开发板上的ENC28J60模块。然后把商家的例程烧进去后发现ENC28J60_Init里的第一个时钟稳定就卡住了。请问大家知道是什么问题么?
贴上 u8 ENC28J60_Init(u8* macaddr) { u16 retry=0; ENC28J60_Reset(); ENC28J60_Write_Op(ENC28J60_SOFT_RESET,0,ENC28J60_SOFT_RESET);//软件复位 while(!(ENC28J60_Read(ESTAT)&ESTAT_CLKRDY))//等待始终稳定 { retry++; delay_ms(1); }; if(retry>=500)return 1;//ENC28J60初始化失败 //截止到这里就出问题了,下面可不看 // do bank 0 stuff // initialize receive buffer // 16-bit transfers,must write low byte first // set receive buffer start address éèÖýóêÕ»o3åÇøμØÖ· 8K×Ö½úèYá¿ NextPacketPtr=RXSTART_INIT; // Rx start //½óêÕ»o3åÆ÷óéò»¸öó2¼t1üàíμÄÑ-»·FIFO »o3åÆ÷113é¡£ //¼Ä′æÆ÷¶ÔERXSTH:ERXSTL oíERXNDH:ERXNDL ×÷ //ÎaÖ¸Õ룬¶¨òå»o3åÆ÷μÄèYá¿oíÆäÔú′æ′¢Æ÷ÖDμÄλÖᣠ//ERXSToíERXNDÖ¸ÏòμÄ×Ö½ú¾ù°üo¬ÔúFIFO»o3åÆ÷Äú¡£ //μ±′óòÔì«íø½ó¿ú½óêÕêy¾Y×Ö½úê±£¬ÕaD©×Ö½ú±»Ë3DòD′èë //½óêÕ»o3åÆ÷¡£ μ«êÇμ±D′èëóéERXND Ö¸ÏòμÄ′æ′¢μ¥Ôa //oó£¬ó2¼t»á×Ô¶ˉ½«½óêÕμÄÏÂò»×Ö½úD′èëóéERXST Ö¸Ïò //μÄ′æ′¢μ¥Ôa¡£ òò′˽óêÕó2¼t½«2»»áD′èëFIFO òÔíaμÄμ¥ //Ôa¡£ //éèÖýóêÕÆeê¼×Ö½ú ENC28J60_Write(ERXSTL,RXSTART_INIT&0xFF); ENC28J60_Write(ERXSTH,RXSTART_INIT>>8); //ERXWRPTH:ERXWRPTL ¼Ä′æÆ÷¶¨òåó2¼tÏòFIFO ÖD //μÄÄĸöλÖÃD′èëÆä½óêÕμ½μÄ×Ö½ú¡£ Ö¸ÕëêÇÖ»¶áμÄ£¬Ôú3é //1|½óêÕμ½ò»¸öêy¾Y°üoó£¬ó2¼t»á×Ô¶ˉ¸üDÂÖ¸Õë¡£ Ö¸Õë¿é //óÃóúÅD¶ÏFIFO Äúê£óà¿Õ¼äμÄ′óD¡ 8K-1500¡£ //éèÖýóêÕ¶áÖ¸Õë×Ö½ú ENC28J60_Write(ERXRDPTL,RXSTART_INIT&0xFF); ENC28J60_Write(ERXRDPTH,RXSTART_INIT>>8); //éèÖýóêÕ½áêø×Ö½ú ENC28J60_Write(ERXNDL,RXSTOP_INIT&0xFF); ENC28J60_Write(ERXNDH,RXSTOP_INIT>>8); //éèÖ÷¢ËíÆeê¼×Ö½ú ENC28J60_Write(ETXSTL,TXSTART_INIT&0xFF); ENC28J60_Write(ETXSTH,TXSTART_INIT>>8); //éèÖ÷¢Ëí½áêø×Ö½ú ENC28J60_Write(ETXNDL,TXSTOP_INIT&0xFF); ENC28J60_Write(ETXNDH,TXSTOP_INIT>>8); // do bank 1 stuff,packet filter: // For broadcast packets we allow only ARP packtets // All other packets should be unicast only for our mac (MAADR) // // The pattern to match on is therefore // Type ETH.DST // ARP BROADCAST // 06 08 -- ff ff ff ff ff ff -> ip checksum for theses bytes=f7f9 // in binary these poitions are:11 0000 0011 1111 // This is hex 303F->EPMM0=0x3f,EPMM1=0x30 //½óêÕ1yÂËÆ÷ //UCEN£oμ¥2¥1yÂËÆ÷ê1Äüλ //μ±ANDOR = 1 ê±£o //1 = Ä¿±êμØÖ·óë±¾μØMAC μØÖ·2»Æ¥ÅäμÄêy¾Y°ü½«±»¶aÆú //0 = ½ûÖ11yÂËÆ÷ //μ±ANDOR = 0 ê±£o //1 = Ä¿±êμØÖ·óë±¾μØMAC μØÖ·Æ¥ÅäμÄêy¾Y°ü»á±»½óêü //0 = ½ûÖ11yÂËÆ÷ //CRCEN£ooó1yÂËÆ÷CRC D£Ñéê1Äüλ //1 = ËùóDCRC ÎTD§μÄêy¾Y°ü¶¼½«±»¶aÆú //0 = 2»¿¼ÂÇCRC êÇ·ñóDD§ //PMEN£o¸ñê½Æ¥Åä1yÂËÆ÷ê1Äüλ //μ±ANDOR = 1 ê±£o //1 = êy¾Y°ü±ØDë·ûoϸñê½Æ¥Åäìõ¼t£¬·ñÔò½«±»¶aÆú //0 = ½ûÖ11yÂËÆ÷ //μ±ANDOR = 0 ê±£o //1 = ·ûoϸñê½Æ¥Åäìõ¼tμÄêy¾Y°ü½«±»½óêü //0 = ½ûÖ11yÂËÆ÷ ENC28J60_Write(ERXFCON,ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN); ENC28J60_Write(EPMM0,0x3f); ENC28J60_Write(EPMM1,0x30); ENC28J60_Write(EPMCSL,0xf9); ENC28J60_Write(EPMCSH,0xf7); // do bank 2 stuff // enable MAC receive //bit 0 MARXEN£oMAC ½óêÕê1Äüλ //1 = ÔêDíMAC ½óêÕêy¾Y°ü //0 = ½ûÖ1êy¾Y°ü½óêÕ //bit 3 TXPAUS£oÔYí£¿ØÖÆÖ¡·¢Ëíê1Äüλ //1 = ÔêDíMAC ·¢ËíÔYí£¿ØÖÆÖ¡£¨óÃóúè«Ë«1¤Ä£ê½ÏÂμÄá÷á¿¿ØÖÆ£© //0 = ½ûÖ1ÔYí£Ö¡·¢Ëí //bit 2 RXPAUS£oÔYí£¿ØÖÆÖ¡½óêÕê1Äüλ //1 = μ±½óêÕμ½ÔYí£¿ØÖÆÖ¡ê±£¬½ûÖ1·¢Ëí£¨Õy3£2ù×÷£© //0 = oöÂÔ½óêÕμ½μÄÔYí£¿ØÖÆÖ¡ ENC28J60_Write(MACON1,MACON1_MARXEN|MACON1_TXPAUS|MACON1_RXPAUS); // bring MAC out of reset //½«MACON2 ÖDμÄMARST λÇåá㣬ê1MAC íË3ö¸′λ×′쬡£ ENC28J60_Write(MACON2,0x00); // enable automatic padding to 60bytes and CRC operations //bit 7-5 PADCFG2ACDFG0£o×Ô¶ˉìî3äoíCRC ÅäÖÃλ //111 = óÃ0 ìî3äËùóD¶ìÖ¡Öá64 ×Ö½ú3¤£¬2¢×·¼óò»¸öóDD§μÄCRC //110 = 2»×Ô¶ˉìî3ä¶ìÖ¡ //101 = MAC ×Ô¶ˉ¼ì2a¾ßóD8100h ààDí×Ö¶ÎμÄVLAN D-òéÖ¡£¬2¢×Ô¶ˉìî3äμ½64 ×Ö½ú3¤¡£èç1û2» //êÇVLAN Ö¡£¬Ôòìî3äÖá60 ×Ö½ú3¤¡£ìî3äoó»1òa×·¼óò»¸öóDD§μÄCRC //100 = 2»×Ô¶ˉìî3ä¶ìÖ¡ //011 = óÃ0 ìî3äËùóD¶ìÖ¡Öá64 ×Ö½ú3¤£¬2¢×·¼óò»¸öóDD§μÄCRC //010 = 2»×Ô¶ˉìî3ä¶ìÖ¡ //001 = óÃ0 ìî3äËùóD¶ìÖ¡Öá60 ×Ö½ú3¤£¬2¢×·¼óò»¸öóDD§μÄCRC //000 = 2»×Ô¶ˉìî3ä¶ìÖ¡ //bit 4 TXCRCEN£o·¢ËíCRC ê1Äüλ //1 = 2»1üPADCFGèçoΣ¬MAC¶¼»áÔú·¢ËíÖ¡μÄÄ©Î2×·¼óò»¸öóDD§μÄCRC¡£ èç1ûADCFG1涨òa //×·¼óóDD§μÄCRC£¬Ôò±ØD뽫TXCRCEN ÖÃ1¡£ //0 = MAC2»»á×·¼óCRC¡£ ¼ì2é×îoó4 ¸ö×Ö½ú£¬èç1û2»êÇóDD§μÄCRC Ôò±¨¸æ¸ø·¢Ëí×′ì¬Ïòá¿¡£ //bit 0 FULDPX£oMAC è«Ë«1¤ê1Äüλ //1 = MAC1¤×÷Ôúè«Ë«1¤Ä£ê½Ï¡£ PHCON1.PDPXMD λ±ØDëÖÃ1¡£ //0 = MAC1¤×÷Ôú°ëË«1¤Ä£ê½Ï¡£ PHCON1.PDPXMD λ±ØDëÇåáã¡£ ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,MACON3,MACON3_PADCFG0|MACON3_TXCRCEN|MACON3_FRMLNEN|MACON3_FULDPX); // set inter-frame gap (non-back-to-back) //ÅäÖ÷DZ3¶Ô±3°ü¼ä¼ä¸ô¼Ä′æÆ÷μÄμí×Ö½ú //MAIPGL¡£ ′ó¶àêyó|óÃê1óÃ12h ±à3ì¸Ã¼Ä′æÆ÷¡£ //èç1ûê1óðëË«1¤Ä£ê½£¬ó|±à3ì·Ç±3¶Ô±3°ü¼ä¼ä¸ô //¼Ä′æÆ÷μĸß×Ö½úMAIPGH¡£ ′ó¶àêyó|óÃê1óÃ0Ch //±à3ì¸Ã¼Ä′æÆ÷¡£ ENC28J60_Write(MAIPGL,0x12); ENC28J60_Write(MAIPGH,0x0C); // set inter-frame gap (back-to-back) //ÅäÖñ3¶Ô±3°ü¼ä¼ä¸ô¼Ä′æÆ÷MABBIPG¡£μ±ê1óà //è«Ë«1¤Ä£ê½ê±£¬′ó¶àêyó|óÃê1óÃ15h ±à3ì¸Ã¼Ä′æ //Æ÷£¬¶øê1óðëË«1¤Ä£ê½ê±Ôòê1óÃ12h ½øDD±à3ì¡£ ENC28J60_Write(MABBIPG,0x15); // Set the maximum packet size which the controller will accept // Do not send packets longer than MAX_FRAMELEN: // ×î′óÖ¡3¤¶è 1500 ENC28J60_Write(MAMXFLL,MAX_FRAMELEN&0xFF); ENC28J60_Write(MAMXFLH,MAX_FRAMELEN>>8); // do bank 3 stuff // write MAC address // NOTE: MAC address in ENC28J60 is byte-backward //éèÖÃMACμØÖ· ENC28J60_Write(MAADR5,macaddr[0]); ENC28J60_Write(MAADR4,macaddr[1]); ENC28J60_Write(MAADR3,macaddr[2]); ENC28J60_Write(MAADR2,macaddr[3]); ENC28J60_Write(MAADR1,macaddr[4]); ENC28J60_Write(MAADR0,macaddr[5]); //ÅäÖÃHYÎaè«Ë«1¤ LEDBÎaà-μçá÷ ENC28J60_PHY_Write(PHCON1,PHCON1_PDPXMD); // no loopback of transmitted frames ½ûÖ1»·»Ø //HDLDIS£oPHY °ëË«1¤»·»Ø½ûÖ1λ //μ±PHCON1.PDPXMD = 1 »òPHCON1.PLOOPBK = 1 ê±£o //′Ëλ¿é±»oöÂÔ¡£ //μ±PHCON1.PDPXMD = 0 ÇòPHCON1.PLOOPBK = 0 ê±£o //1 = òa·¢ËíμÄêy¾Y½öí¨1yË«½êÏß½ó¿ú·¢3ö //0 = òa·¢ËíμÄêy¾Y»á»·»Øμ½MAC 2¢í¨1yË«½êÏß½ó¿ú·¢3ö ENC28J60_PHY_Write(PHCON2,PHCON2_HDLDIS); // switch to bank 0 //ECON1 ¼Ä′æÆ÷ //¼Ä′æÆ÷3-1 Ëùê¾ÎaECON1 ¼Ä′æÆ÷£¬ËüóÃóú¿ØÖÆ //ENC28J60 μÄÖ÷òa1|Äü¡£ ECON1 ÖD°üo¬½óêÕê1Äü¡¢·¢ //ËíÇëÇó¡¢DMA ¿ØÖÆoí′æ′¢ÇøÑ¡Ôñλ¡£ ENC28J60_Set_Bank(ECON1); // enable interrutps //EIE£o òÔì«íøÖD¶ÏÔêDí¼Ä′æÆ÷ //bit 7 INTIE£o 諾ÖINT ÖD¶ÏÔêDíλ //1 = ÔêDíÖD¶Ïê¼tÇy¶ˉINT òy½Å //0 = ½ûÖ1ËùóDINT òy½ÅμÄ»î¶ˉ£¨òy½Åê¼ÖÕ±»Çy¶ˉÎa¸ßμçƽ£© //bit 6 PKTIE£o ½óêÕêy¾Y°ü′y′|àíÖD¶ÏÔêDíλ //1 = ÔêDí½óêÕêy¾Y°ü′y′|àíÖD¶Ï //0 = ½ûÖ1½óêÕêy¾Y°ü′y′|àíÖD¶Ï ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,EIE,EIE_INTIE|EIE_PKTIE); // enable packet reception //bit 2 RXEN£o½óêÕê1Äüλ //1 = í¨1yμ±Ç°1yÂËÆ÷μÄêy¾Y°ü½«±»D′èë½óêÕ»o3åÆ÷ //0 = oöÂÔËùóD½óêÕμÄêy¾Y°ü ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,ECON1,ECON1_RXEN); if(ENC28J60_Read(MAADR5)== macaddr[0])return 0;//3õê¼»ˉ3é1| else return 2; } |
|
相关推荐
1个回答
|
|
while(!(ENC28J60_Read(ESTAT)&ESTAT_CLKRDY))//等待时钟稳定
{ retry++; delay_ms(1); }; 程序还是能运行的,就是这里一直加 |
|
|
|
只有小组成员才能发言,加入小组>>
如何使用STM32+nrf24l01架构把有线USB设备无线化?
2568 浏览 7 评论
请问能利用51单片机和nRF24L01模块实现实时语音无线传输吗?
2360 浏览 5 评论
3207 浏览 3 评论
2836 浏览 8 评论
为什么ucosii上移植lwip后系统进入了HardFault_Handler?
2787 浏览 4 评论
请教各位大咖:有没有接收频率32M左右的芯片推荐的?先感谢啦!
662浏览 1评论
899浏览 0评论
1021浏览 0评论
665浏览 0评论
495浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 17:37 , Processed in 1.270484 second(s), Total 49, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号