lwip lwip发送数据和接收可以同时吗

开封威利流量仪表有限公司
地址:河南省开封市北郊工业园区6号
邮编:475100
售后电话: 400-618-
你的位置:
>>   stm32
stm32 lwip 做客户端程序,可是怎么都建立不了连接,都不会进TcpCli_Connected这个回调函数 麻烦大虾指点
来源:开封威利流量仪表_官网_MGG是我公司注册商标 | 发布时间: 12:06:34 |
浏览次数:
stm32 lwip 做客户端程序,可是怎么都建立不了连接,都不会进TcpCli_Connected这个回调函数 麻烦大虾指点,硬件应该没有问题,pc的IP:192.168.1.16,端口:23
是我哪里写掉了什么啊?main()中的:函数/*初始化 以太网SPI接口*/ENC_SPI_Init(); /*初始化systick,用于定时轮询输入或给LWIP提供定时*/SysTick_Init();/* 初始化LWIP协议栈*/LwIP_Init();
while ( 1 ){
TCP_Client_Init();Delay1(1000000UL);Delay1(1000000UL);Delay1(1000000UL);Delay1(1000000UL);
}具体的子函数:/******* 这是一个回调函数,当TCP客户端请求的连接建立时被调用********/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 *C struct ip_ IP4_ADDR(&ipaddr,192,168,1,16); Clipcb = tcp_new();
// 建立通信的TCP控制块(Clipcb) tcp_bind(Clipcb,IP_ADDR_ANY,23);
// 绑定本地IP地址和端口号 iris_pcb=C //the mathod is wrong //by iris
tcp_connect(Clipcb,&ipaddr,23,TcpCli_Connected);}unsigned long iris_IP[5]={192, 168, 1, 18};void LwIP_Init( void ){// struct ip_ struct ip_ struct ip_ /*调用LWIP初始化函数, 初始化网络接口结构体链表、内存池、pbuf结构体*/ lwip_init(); #if LWIP_DHCP
//若使用DHCP协议 ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0;#else///*//by iris // IP4_ADDR(&ipaddr, 192, 168, 0, 18); //设置网络接口的ip地址 IP4_ADDR(&netmask, 255, 255, 255, 0);//子网掩码 IP4_ADDR(&gw, 192, 168, 0, 1);//网关*///by iris //// IP4_ADDR(&ipaddr, 192, 168, 1, 18); //设置网络接口的ip地址 IP4_ADDR(&ipaddr, iris_IP[0], iris_IP[1], iris_IP[2], iris_IP[3]); //设置网络接口的ip地址 IP4_ADDR(&netmask, 255, 255, 255, 0);//子网掩码 IP4_ADDR(&gw, 192, 168, 1, 1);//网关#endif
/*初始化enc28j60与LWIP的接口,参数为网络接口结构体、ip地址、 子网掩码、网关、网卡信息指针、初始化函数、输入函数*/ netif_add(&enc28j60, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input); /*把enc28j60设置为默认网卡 .*/ netif_set_default(&enc28j60);#if LWIP_DHCP
//若使用了DHCP /* Creates a new DHCP client for this interface on the first call. Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at the predefined regular intervals after starting the client. You can peek in the netif->dhcp struct for the actual DHCP status.*/ dhcp_start(&enc28j60);
//启动DHCP#endif /* When the netif is fully configured this function must be called.*/ netif_set_up(&enc28j60); //使能enc28j60接口}#define ENC_SPI_Init
SPI1_Initvoid SPI1_Init(void){ SPI_InitTypeDef SPI_InitS GPIO_InitTypeDef GPIO_InitS /* Enable SPI1 and GPIOA clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, F_ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, F_ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;//CS GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure); //BY IRIS
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Configure SPI1 pins: NSS, SCK, MISO and MOSI */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //by iris
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//上拉输入 GPIO_Init(GPIOA, &GPIO_InitStructure); //by iris
/* SPI1 configuration */ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullD SPI_InitStructure.SPI_Mode = SPI_Mode_M SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_L SPI_InitStructure.SPI_CPHA = SPI_CPHA_1E SPI_InitStructure.SPI_NSS = SPI_NSS_S SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); /* Enable SPI1 */ SPI_Cmd(SPI1, F_ENABLE);}
-->这篇文章被编辑了 2 次. 最近一次更新是在
学习频道 推荐精贴(上一个):ALIENTEK 战舰ENC28J60 LWIP和UIP补充例程(LWIP WEB有惊喜)
学习频道 推荐精贴(下一个):【ALIENTEK 战舰STM32开发板例程系列连载+教学】第五十七章 ENC28J60网络实验
进入学习频道(查看所有相关):STM32-F0/F1/F2学习->配套学习模块->通信-以太网
TAG:[标签:TAG]
 上一篇:
 下一篇: 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
正在努力加载中...
LwIP的RAW_API接口及编程指南
下载积分:100
内容提示:LwIP的RAW_API接口及编程指南
文档格式:PDF|
浏览次数:120|
上传日期: 09:46:47|
文档星级:
该用户还上传了这些文档
LwIP的RAW_API接口及编程指南
官方公共微信LwIP编程指南_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
LwIP编程指南
上传于||暂无简介
阅读已结束,如果下载本文需要使用
想免费下载本文?
下载文档到电脑,查找使用更方便
还剩23页未读,继续阅读
你可能喜欢lwip 作为服务器
同个Ip地址多次重复连接服务器
[问题点数:40分,结帖人asd046012]
lwip 作为服务器
同个Ip地址多次重复连接服务器
[问题点数:40分,结帖人asd046012]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。

我要回帖

更多关于 lwip udp发送数据 的文章

 

随机推荐