RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|
RCC_APB2Periph_GPIOF|RCC_APB2Periph_GPIOG,ENABLE); //ê1ÄüGPIOD E F Gê±Öó
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE); //ê1ÄüFSMCê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //ê1Äü¸′óÃ1|Äüê±Öó
在你们那里买了一块,集成DM9000,测试没问题,后来我又买了一块stm32最小系统,和一个DM9000的模块,接在一起,就出现上面那些错误了
u8 DM9000_Init(void)
{
u32 temp;
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef ReadWriteTiming; //DM9000μĶáD′ê±Dò
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE|
RCC_APB2Periph_GPIOF|RCC_APB2Periph_GPIOG,ENABLE); //ê1ÄüGPIOD E F Gê±Öó
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE); //ê1ÄüFSMCê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //ê1Äü¸′óÃ1|Äüê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //PD7 íÆíìêä3ö dm9000¸′λ-RST
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//íÆíìêä3ö
GPIO_Init(GPIOD,&GPIO_InitStructure);
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //PG6 íÆíìêä3ö dm90003õê¼»ˉ-INT
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //éÏà-êäèë
// GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //PG6 íÆíìêä3ö
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //éÏà-êäèë
GPIO_Init(GPIOG,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|
GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_14|GPIO_Pin_15; //PD0 1 4 5 8 9 10 14 15¸′óÃ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//¸′óÃíÆíìêä3ö
GPIO_Init(GPIOD,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|
GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //PE7 8 9 10 11 12 13 14 15¸′óÃ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//¸′óÃíÆíìêä3ö
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //PF13¸′óÃ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//¸′óÃíÆíìêä3ö
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PG9¸′óÃ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//¸′óÃíÆíìêä3ö
GPIO_Init(GPIOG,&GPIO_InitStructure);
//PG6ía2¿ÖD¶Ï£¬ÖD¶ÏÏß6
GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource6);
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line6); //Çå3yÖD¶ÏÏß61òÆe±ê־λ
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //ía2¿ÖD¶ÏÏß6
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //ÇàÕ¼óÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //×óóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
ReadWriteTiming.FSMC_AddressSetupTime = 0; //μØÖ·½¨á¢ê±¼ä
ReadWriteTiming.FSMC_AddressHoldTime = 0; //μØÖ·±£3Öê±¼ä
ReadWriteTiming.FSMC_DataSetupTime = 3; //êy¾Y½¨á¢ê±¼ä
ReadWriteTiming.FSMC_BusTurnAroundDuration = 0x00; //×üÏ߻ָ′ê±¼ä
ReadWriteTiming.FSMC_CLKDivision = 0x00; //ê±Öó·ÖÆμòò×ó
ReadWriteTiming.FSMC_DataLatency = 0x00; //êy¾Y2úéúê±¼ä
ReadWriteTiming.FSMC_AccessMode = FSMC_AccessMode_A;//ê1óÃÄ£ê½A---NOR¿ØÖÆÆ÷ê±Dò
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; //NE2 ê1óÃáËFSMCμÄbank1μÄ×ó°å¿é2
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //½ûÖ1μØÖ·êy¾YÏ߸′óÃ
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; //′æ′¢Æ÷ààDíÎaSRAM
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; //′æ′¢Æ÷êy¾Y¿íλÎa16λ
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; //1رÕí»·¢Ä£ê½·ÃÎê
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; //1رÕòì2½μè′y
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; //μè′yDÅoÅóÅÏ輶£¬Ö»óDÔúê1Äüí»·¢·ÃÎêÄ£ê½2ÅóDD§
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; //1رÕWrapped burst access mode,Ö»óDÔúê1Äüí»·¢·ÃÎêÄ£ê½2ÅóDD§
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; //μè′yDÅoÅéèÖã¬Ö»óDÔúê1Äüí»·¢·ÃÎêÄ£ê½2ÅóDD§
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; //ê1ÄüÕa¸öBANKμÄD′2ù×÷
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; //ê1Äü»òÕß1رÕμè′yDÅoÅéèÖã¬Ö»óDÔúê1Äüí»·¢·ÃÎêÄ£ê½2ÅóDD§
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; //1رÕExtend Mode
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; //1رÕD′burst mode
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &ReadWriteTiming; //¶á2ù×÷ê±Dò2Îêy
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &ReadWriteTiming; //D′2ù×÷ê±Dò2Îêy
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); //3õê¼»ˉ
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2,ENABLE); //ê1ÄüFSMCμÄBank1_Bank1_NORSRAM2
temp=*(vu32*)(0x1FFFF7E8); //»ñè¡STM32μÄΨò»IDμÄÇ°24λ×÷ÎaMACμØÖ·oóèy×Ö½ú
dm9000cfg.mode=DM9000_AUTO;
dm9000cfg.queue_packet_len=0;
//DM9000μÄSRAMμÄ·¢Ëíoí½óêÕÖ¸Õë×Ô¶ˉ·μ»Øμ½¿aê¼μØÖ·£¬2¢Çò¿aÆô½óêÕÖD¶Ï
dm9000cfg.imr_all = IMR_PAR|IMR_PRI;
//3õê¼»ˉMACμØÖ·
dm9000cfg.mac_addr[0]=20;
dm9000cfg.mac_addr[1]=16;
dm9000cfg.mac_addr[2]=10;
dm9000cfg.mac_addr[3]=(temp>>16)&0XFF; //μíèy×Ö½úóÃSTM32μÄΨò»ID
dm9000cfg.mac_addr[4]=(temp>>8)&0XFFF;
dm9000cfg.mac_addr[5]=temp&0XFF;
//3õê¼»ˉ×é2¥μØÖ·
dm9000cfg.multicase_addr[0]=0Xff;
dm9000cfg.multicase_addr[1]=0Xff;
dm9000cfg.multicase_addr[2]=0Xff;
dm9000cfg.multicase_addr[3]=0Xff;
dm9000cfg.multicase_addr[4]=0Xff;
dm9000cfg.multicase_addr[5]=0Xff;
dm9000cfg.multicase_addr[6]=0Xff;
dm9000cfg.multicase_addr[7]=0Xff;
DM9000_Reset(); //¸′λDM9000
delay_ms(100);
temp=DM9000_Get_DeiviceID(); //»ñè¡DM9000ID
printf("DM9000 ID:%#x ",temp);
if(temp!=DM9000_ID) return 1; //¶áè¡ID′íÎó
DM9000_Set_PHYMode(dm9000cfg.mode); //éèÖÃHY1¤×÷Ä£ê½
DM9000_WriteReg(DM9000_NCR,0X00);
DM9000_WriteReg(DM9000_TCR,0X00); //·¢Ëí¿ØÖƼÄ′æÆ÷Çåáã
DM9000_WriteReg(DM9000_BPTR,0X3F);
DM9000_WriteReg(DM9000_FCTR,0X38);
DM9000_WriteReg(DM9000_FCR,0X00);
DM9000_WriteReg(DM9000_SMCR,0X00); //ìØêaÄ£ê½
DM9000_WriteReg(DM9000_NSR,NSR_WAKEST|NSR_TX2END|NSR_TX1END);//Çå3y·¢Ëí×′ì¬
DM9000_WriteReg(DM9000_ISR,0X0F); //Çå3yÖD¶Ï×′ì¬
DM9000_WriteReg(DM9000_TCR2,0X80); //ÇD»»LEDμ½mode1
//éèÖÃMACμØÖ·oí×é2¥μØÖ·
DM9000_Set_MACAddress(dm9000cfg.mac_addr); //éèÖÃMACμØÖ·
DM9000_Set_Multicast(dm9000cfg.multicase_addr); //éèÖÃ×é2¥μØÖ·
DM9000_WriteReg(DM9000_RCR,RCR_DIS_LONG|RCR_DIS_CRC|RCR_RXEN);
DM9000_WriteReg(DM9000_IMR,IMR_PAR);
temp=DM9000_Get_SpeedAndDuplex(); //»ñè¡DM9000μÄᬽóËù¶èoíË«1¤×′ì¬
if(temp!=0XFF) //ᬽó3é1|£¬í¨1y′®¿úÏÔê¾á¬½óËù¶èoíË«1¤×′ì¬
{
printf("DM9000 Speed:%dMbps,Duplex:%s duplex mode ",(temp&0x02)?10:100,(temp&0x01)?"Full":"Half");
}else printf("DM9000 Establish Link Failed! ");
DM9000_WriteReg(DM9000_IMR,dm9000cfg.imr_all); //éèÖÃÖD¶Ï
return 0;
}
贴了,在下面
一周热门 更多>