青檬 发表于 2012-1-12 08:49:52

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

/* Private typedef -----------------------------------------------------------*/
static struct tcp_pcb *TcpPCB;
#define TCP_PORT  1234
uint8_t test={1,2,3,4,5,6,7,8,9,0};
uint8_t RX;
uint32_t y;
extern uint8_t LocalDisplay;
/* 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 ={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;
}

青檬 发表于 2012-1-12 08:50:55

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

每次都是通讯2920次,不知道是哪里没有设置正确。有谁碰到同样的问题?
页: [1]
查看完整版本: STM32F107使用LWIP协议栈通讯,过会就断了,求高手