怎么没有数据接收啊?? 求哥哥姐姐们帮忙啊

2019-03-24 14:14发布

#include <string.h>#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 "driverlib/gpio.h"#include "driverlib/sysctl.h"
#include "utils/lwiplib.h"#include "utils/ustdlib.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;static const unsigned char TCP_TestData[]="This is LwIP TCP Client 在Luminary Cortex-M3上的测试! ";#define SYSTICKHZ 100#define SYSTICKMS (1000 / SYSTICKHZ)#define SYSTICKUS (1000000 / SYSTICKHZ)#define SYSTICKNS (1000000000 / SYSTICKHZ)
void Delay(unsigned long ulVal) /* 利用循环产生一定的延时 */{while ( --ulVal != 0 );}
err_t TcpCli_Connected(void *arg,struct tcp_pcb *pcb,err_t err){tcp_write(pcb,TCP_TestData,sizeof(TCP_TestData),0); /* 发送数据 */tcp_close(pcb);return ERR_OK;}

void TCP_Client_Init(){  struct tcp_pcb *Clipcb;  struct ip_addr ipaddr;    IP4_ADDR(&ipaddr,192,168,0,127);    Clipcb = tcp_new();                       // 建立通信的TCP控制块(Clipcb)     tcp_bind(Clipcb,IP_ADDR_ANY,1026);       // 绑定本地IP地址和端口号     tcp_connect(Clipcb,&ipaddr,1026,TcpCli_Connected);}



voidSysTickIntHandler(void){
lwIPTimer(SYSTICKMS);
}voidenet_udp(void){    struct ip_addr ulIPAddr,ulNetMask,ulGWAddr;      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); while(1){    TCP_Client_Init();    SysCtlDelay(SysCtlClockGet()/3); }}

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
6条回答
Study_Stellaris
1楼-- · 2019-03-24 20:31
TcpCli_Connected()没看到
jxndcl301
2楼-- · 2019-03-25 00:02
< :TI_MSP430_内容页_SA7 --> 你这问题问的…… 出现问题把代码一贴!论坛里也有很多网友学习uIP的资料,http://bbs.eeworld.com.cn/search.php?searchid=30&orderby=lastpost&ascdesc=desc&searchsubmit=yes 仔细看看别人的笔记,在研究下自己的。祝你进步……
zyjstrong
3楼-- · 2019-03-25 04:31
 精彩回答 2  元偷偷看……
zyjstrong
4楼-- · 2019-03-25 06:22
#include <string.h>
#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 "driverlib/gpio.h"
#include "driverlib/sysctl.h"

#include "utils/lwiplib.h"
#include "utils/ustdlib.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 TCP_TestData[]="This is LwIP TCP Client测试! ";
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)
#define SYSTICKUS (1000000 / SYSTICKHZ)
#define SYSTICKNS (1000000000 / SYSTICKHZ)


void
SysTickIntHandler(void)
{
   
  lwIPTimer(SYSTICKMS);
}

void Delay(unsigned long ulVal) /* 利用循环产生一定的延时 */
{
while ( --ulVal != 0 );
}

typedef struct
{
        unsigned long ulRetryCount;       
        tBoolean bCONTROLSent;       
} tAPPState;

static err_t App_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
        LWIP_UNUSED_ARG(len);
        tcp_write(pcb,TCP_TestData,sizeof(TCP_TestData),0);
        tcp_sent(pcb, App_sent);
       
        return ERR_OK;
}

err_t TcpCli_Connected(void *arg,struct tcp_pcb *pcb,err_t err)
{
tcp_write(pcb,TCP_TestData,sizeof(TCP_TestData),0); /* 发送数据 */
tcp_sent(pcb, App_sent);
tcp_close(pcb);
return ERR_OK;                                                                                                                                            
}



void TCP_Client_Init()
{
  struct tcp_pcb *Clipcb;
  struct ip_addr ipaddr;

  IP4_ADDR(&ipaddr,192,168,0,127);
  
  Clipcb = tcp_new();                       // 建立通信的TCP控制块(Clipcb)
  
  tcp_bind(Clipcb,IP_ADDR_ANY,1026);       // 绑定本地IP地址和端口号
  tcp_connect(Clipcb,&ipaddr,1026,TcpCli_Connected);
  

}

void
enet_udp(void)
{
   struct ip_addr ulIPAddr,ulNetMask,ulGWAddr;
      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);

while(1)
{
    TCP_Client_Init();
    Delay(1000000UL);  
    Delay(1000000UL);
    Delay(1000000UL);
}


}
   
Study_Stellaris
5楼-- · 2019-03-25 08:18
检查 PC 机的 IP 地址和 8962 的 IP 地址和端口
zyjstrong
6楼-- · 2019-03-25 12:59
 精彩回答 2  元偷偷看……

一周热门 更多>

相关问题

    相关文章