G:\Snipaste_2022-05-25_16-20-39.png
G:\Snipaste_2022-05-25_16-21-40.png
这是芯片初始化和配置printf("网络ch395 初始化开始。。。\n\r");
spi_net_init();
//复位 CH395
CH395_RST();
/*获取芯片版本*/
while((ch395_version = CH395CMDGetVer()) < 0x40)
{
printf("CH395CMDGetVer ERR\r\n");
delay_1ms(100);
}
printf("CH395CMDGetVer %d\r\n",ch395_version);
/*测试命令,按位取反返回说明测试通过*/
while(CH395CMDCheckExist(0x55) != 0xaa)
{
printf("\r\nCH395CMDCheck ERR\r\n");
delay_1ms(100);
}
printf("测试成功,存在\r\n");
/*初始化模块:成功返回 0 */
while(CH395CMDInitCH395() != 0)
{
printf("\r\nCH395CMDInitCH395 ERR\r\n");
delay_1ms(100);
}
printf("芯片初始化成功\r\n");
/*初始化UDP*/
while( ch395_socket_udp_init(SocketIndex, SocketDesIP, SocketDesPort, SocketSourPort) != 0)
{
printf("\r\nch395_socket_udp_init ERR\r\n");
delay_1ms(100);
}
printf("UDP初始化成功\r\n");
CH395EEPROMTEST();
printf("CH395 EEPROM测试完成\r\n");
CH395GetIPInf(buf);//获取IP,网关和子网掩码
printf("IP:%d.%d.%d.%d\r\n", buf[0], buf[1], buf[2], buf[3]);
printf("GWIP:%d.%d.%d.%d\r\n", buf[4], buf[5], buf[6], buf[7]);
printf("Mask:%d.%d.%d.%d\r\n", buf[8], buf[9], buf[10], buf[11]);
printf("DNS1:%d.%d.%d.%d\r\n", buf[12], buf[13], buf[14], buf[15]);
printf("DNS2:%d.%d.%d.%d\r\n", buf[16], buf[17], buf[18], buf[19]);
#endif
然后udp中断就卡在这里了void ch395_socket_udp_interrupt(uint8_t sockindex)
{
uint8_t sock_int_socket;
uint16_t len;
/* 获取socket 的中断状态 */
sock_int_socket = CH395GetSocketInt(sockindex);
/* 发送缓冲区空闲,可以继续写入要发送的数据 */
if(sock_int_socket & SINT_STAT_SENBUF_FREE)
{
printf("发送缓冲区空闲\r\n");
}
// CH395UDPSendTo("347GDFGRT45", 12, SocketDesIP, SocketDesPort, 0);
/* 发送完成中断 */
if(sock_int_socket & SINT_STAT_SEND_OK)
{
printf("发送完成中断\r\n");
}
/* 接收数据中断 */
if(sock_int_socket & SINT_STAT_RECV)
{
len = CH395GetRecvLength(sockindex);/* 获取当前缓冲区内数据长度 */
printf("\r\nreceive len = %d\r\n", len);
if(len == 0)return;
if(len > recv_buff_len)len = recv_buff_len;
CH395GetRecvData(sockindex, len, recv_buff); /* 读取数据 */
/*把接收的数据返回给UDP*/
CH395SendData(sockindex, recv_buff, len);
//也可以使用下面的函数发送数据
CH395UDPSendTo(recv_buff, len, SocketDesIP, SocketDesPort, sockindex);
/*使用串口打印接收的数据*/
// PutData(&rb_t_usart1_send,recv_buff,len);
// USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
}
}
|