你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 3314|回复: 1

STM32F107使用LWIP协议栈通讯,过会就断了,求高手

[复制链接]

48

主题

209

回帖

0

蝴蝶豆

金牌会员

最后登录
1970-1-1
发表于 2012-1-12 08:49:52 | 显示全部楼层 |阅读模式
/* Private typedef -----------------------------------------------------------*/
static struct tcp_pcb *TcpPCB;
#define TCP_PORT  1234
uint8_t test[10]={1,2,3,4,5,6,7,8,9,0};
uint8_t RX[100];
uint32_t y;
extern uint8_t LocalDisplay[82];
/* Private function prototypes -----------------------------------------------*/
void LwIP_Init(void);
err_t tcp_client_accept(void *arg, struct tcp_pcb *pcb, err_t err);
static err_t tcp_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
/* Private functions ---------------------------------------------------------*/
/**
  * @brief  Initialize the client application.
  * @param  None
  * @retval None
  */
void tcp_client_init(void)
{
  struct tcp_pcb *tpcb;
  struct ip_addr ipaddr;
  IP4_ADDR(&ipaddr, 192, 168, 1, 125);  //远程主机
  /* Create a new TCP control block  */
  tpcb = tcp_new();
  /* Assign to the new pcb a local IP address and a port number */
  tcp_bind(tpcb, IP_ADDR_ANY, TCP_PORT);
  /* Connect to the server: send the SYN */
  tcp_connect(tpcb, &ipaddr, TCP_PORT, tcp_client_accept);
  

}

 /**
  * @brief  This funtion is called when a TCP connection has been established on the port TCP_PORT.
  * @param  arg user supplied argument
  * @param  pcb the tcp_pcb which accepted the connection
  * @param  err error value
  * @retval ERR_OK
  */
err_t tcp_client_accept(void *arg, struct tcp_pcb *tpcb, err_t err)
{
  /* Specify the function that should be called when the TCP connection receives data */
  tcp_recv(tpcb, tcp_client_recv);
  return ERR_OK; 
}
/**
  * @brief  This function is called when a data is received over the TCP_PORT.
  *         The received data contains the number of the led to be toggled.
  * @param  arg user supplied argument
  * @param  pcb the tcp_pcb which accepted the connection
  * @param  p the packet buffer that was received
  * @param  err error value
  * @retval ERR_OK
  */
static err_t tcp_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
   uint8_t Data_len;
   uint8_t hello[1] ={2};
   /* Read Data*/
   Data_len = p->len;
   memcpy(RX, p->payload, Data_len);
   tcp_write(tpcb,&hello,sizeof(hello),1); 
   tcp_output(tpcb);
  /* Free the p buffer */
   pbuf_free(p);
   return ERR_OK;
}
<
回复

使用道具 举报

48

主题

209

回帖

0

蝴蝶豆

金牌会员

最后登录
1970-1-1
 楼主| 发表于 2012-1-12 08:50:55 | 显示全部楼层

RE:STM32F107使用LWIP协议栈通讯,过会就断了,求高手

每次都是通讯2920次,不知道是哪里没有设置正确。有谁碰到同样的问题?
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版