小弟用自己做的板子(主芯片是9L97的和9B96相似)从最基本的LWip调试以太网模块,我用论坛里academic的帖子里的第一个程序https://bbs.eeworld.com.cn/thread-222963-1-2.html编译通过后下载到板子里,用交叉网线把开发板和PC相连,程序下载进去以后 PC机右下角网络连接的小红叉消失了,但是 我在PC上面ping 192.168.0.100 却ping不通。不知道是哪里出现了错误?急切盼望高手出现指点一二 。
下面附上我所用的程序:
#include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_nvic.h" #include "inc/hw_types.h" #include "inc/hw_sysctl.h"
#include "driverlib/ethernet.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" #include "driverlib/systick.h" #include "utils/lwiplib.h"
#define My_Mac_ID {0X00,0x14,0x97,0x0F,0x1D,0xE3} //存储以太网控制器的物理地址,即MAC地址
#define MY_IP_ID {192,168,0,100} //以太网通信的IP地址 #define IP_MARK_ID {255,255,255,0} //255.255.255.0,子网掩码 #define MY_GATEWAY_ID {192,168,0,1} //以太网通信的网关地址 static const unsigned char pucMACAddress[]=My_Mac_ID; static const unsigned char IPAddress[] = MY_IP_ID; static const unsigned char NetMaskAddr[] = IP_MARK_ID; static const unsigned char GwWayAddr[] = MY_GATEWAY_ID;
const static unsigned char UDPData[]="LwIP UDP客户端在Luminary微控制器上的测试\r\n";
#define SYSTICKHZ 100 #define SYSTICKMS (1000 / SYSTICKHZ) #define SYSTICKUS (1000000 / SYSTICKHZ) #define SYSTICKNS (1000000000 / SYSTICKHZ)
void SysTickIntHandler(void) { lwIPTimer(SYSTICKMS);
}
int main(void) { struct ip_addr ulIPAddr,ulNetMask,ulGWAddr; struct udp_pcb *Pcb1; struct ip_addr ipaddr1; struct pbuf *p;
if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); }
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH); SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);
SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ); SysTickEnable(); SysTickIntEnable();
IntMasterEnable(); IP4_ADDR(&ulIPAddr,IPAddress[3],IPAddress[2],IPAddress[1],IPAddress[0]); IP4_ADDR(&ulNetMask,NetMaskAddr[3],NetMaskAddr[2],NetMaskAddr[1],NetMaskAddr[0]); IP4_ADDR(&ulGWAddr,GwWayAddr[3],GwWayAddr[2],GwWayAddr[1],GwWayAddr[0]); lwIPInit(pucMACAddress,ulIPAddr.addr, ulNetMask.addr, ulGWAddr.addr, IPADDR_USE_STATIC); p = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM); p->payload=(void *)UDPData; IP4_ADDR(&ipaddr1,192,168,0,127); //这里是PC机的IP地址。 Pcb1 = udp_new(); udp_bind(Pcb1,IP_ADDR_ANY,1025); /* 绑定到本地IP地址,设端口为1025,客户端一般为偶数。*/
udp_connect(Pcb1,&ipaddr1,1025); /* 连接PC机上的1025号端口,其实服务器的端口一般为奇数。*/
while(1) { udp_send(Pcb1,p); SysCtlDelay(SysCtlClockGet()/3); }
}
|