/* 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; } |
STM32F107+LWIP---如何检查tcp通讯断开?并重新连接
有没有用过数字式mems麦克风的,想问下SPI通讯的问题
stm32f103 CAN通讯多帧发送问题?
STM32F107作为USB主机模拟串口通讯不成功(采用PL2303芯片)
STM32F103C8 LIN通讯例程
求助,丐版J-Link通讯不上
ethernet可以与ethercat通讯吗?
LIS3DH SPI 通讯问题
STM32F373 CAN通讯问题CAN_FLAG_LEC
请教高手看看,STM32F1的多机通讯,地址匹配唤醒问题
RE:STM32F107使用LWIP协议栈通讯,过会就断了,求高手