中级会员
 
- 积分
- 210
- 金钱
- 210
- 注册时间
- 2020-10-24
- 在线时间
- 57 小时
|
10金钱
手上有个老哥留下的板子,用的是STM32F103RET6+dm9000A+FREERTOS ,因为没有FSMC所以用的IO口模拟驱动,然后我发现板子上单片机引脚不够,DM9000A的中断引脚没接,看了下程序是参照原子写的。
现在的问题是我串口能正常读取出芯片id,但是连接速度和双工状态读不出来,串口显示建立连接失败,一直找不出什么问题,有没有大佬来指点一下。。
u8 DM9000_Init(void)
{
u32 temp;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD,ENABLE); //使能GPIOA B C D时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //使能复用功能时钟
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE); //GPIO_Remap_SWJ_Disable 由于需要用到A15管脚
/**************************************************************************************************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //PC4 推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //PA7
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_12; //PB0 12
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5; //PC5
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //PA8
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //PB13 14 15
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9; //PC6 7 8 9
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_15; //PA11 12 15
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5; //PB3 4 5
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //PC12
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PD2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
GPIO_Init(GPIOD,&GPIO_InitStructure);
/*******************************************************************************************************/
temp=*(vu32*)(0x1FFFF7E8); //获取STM32的唯一ID的前24位作为MAC地址后三字节
dm9000cfg.mode=DM9000_AUTO;
dm9000cfg.queue_packet_len=0;
//DM9000的SRAM的发送和接收指针自动返回到开始地址,并且开启接收中断
dm9000cfg.imr_all = IMR_PAR|IMR_PRI;
//初始化MAC地址
dm9000cfg.mac_addr[0]=2;
dm9000cfg.mac_addr[1]=0;
dm9000cfg.mac_addr[2]=0;
dm9000cfg.mac_addr[3]=(temp>>16)&0XFF; //低三字节用STM32的唯一ID
dm9000cfg.mac_addr[4]=(temp>>8)&0XFFF;
dm9000cfg.mac_addr[5]=temp&0XFF;
//初始化组播地址
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
vTaskDelay(100);
while(1)
{
temp=DM9000_Get_DeiviceID(); //获取DM9000ID
printf("DM9000 ID:%#x\r\n",temp);
if(temp==DM9000_ID) break; //读取ID错误
vTaskDelay(10);
}
DM9000_Set_PHYMode(dm9000cfg.mode); //设置PHY工作模式
DM9000_iow(DM9000_NCR,0X00);
DM9000_iow(DM9000_TCR,0X00); //发送控制寄存器清零
DM9000_iow(DM9000_BPTR,0X3F);
DM9000_iow(DM9000_FCTR,0X38);
DM9000_iow(DM9000_FCR,0X00);
DM9000_iow(DM9000_SMCR,0X00); //特殊模式
DM9000_iow(DM9000_NSR,NSR_WAKEST|NSR_TX2END|NSR_TX1END);//清除发送状态
DM9000_iow(DM9000_ISR,0X0F); //清除中断状态
DM9000_iow(DM9000_TCR2,0X80); //切换LED到mode1
//设置MAC地址和组播地址
DM9000_Set_MACAddress(dm9000cfg.mac_addr); //设置MAC地址
DM9000_Set_Multicast(dm9000cfg.multicase_addr); //设置组播地址
DM9000_iow(DM9000_RCR,RCR_DIS_LONG|RCR_DIS_CRC|RCR_RXEN);
DM9000_iow(DM9000_IMR,IMR_PAR);
temp=DM9000_Get_SpeedAndDuplex(); //获取DM9000的连接速度和双工状态
if(temp!=0XFF) //连接成功,通过串口显示连接速度和双工状态
{
printf("DM9000 Speed:%dMbps,Duplex:%s duplex mode\r\n",(temp&0x02)?10:100,(temp&0x01)?"Full":"Half");
}else printf("DM9000 Establish Link Failed!\r\n");
DM9000_iow(DM9000_IMR,dm9000cfg.imr_all); //设置中断
return 0;
}
串口输出
|
最佳答案
查看完整内容[请看2#楼]
找到问题了,之前那个老哥在网络变压器的四个差分线上串了49.9的电阻,最开始我以为没问题因为我之前用W5100的时候官方原理图上也是串进去。不过把串的电阻去掉,通过49.9电阻和电容接地后问题就解决了。原子的原理图上也是如此。欸,这破问题折腾了两周。不过我仍然不清楚到底是因为换网络变压器的原因,还是换了网络芯片的原因。
|