2025年W5500+STM32F103C8T6进行TCP通信(modbus)

W5500+STM32F103C8T6进行TCP通信(modbus)一 W5500 以太网模块介绍 iren W5500 模块是一款基于 WIZnet W5500 芯片的以太网模块 是泥人电子继 Niren W5100 模块后设计的一块性能更好 性价比更高的以太网模块 二 使用测试工具调试 使用 TCP amp UDP 测试工具进行调试 PC5 引脚可以更换为其它引脚 在 keil 中编译运行后 打开调试工具

大家好,我是讯享网,很高兴认识大家。

一.W5500以太网模块介绍

iren_W5500模块是一款基于WIZnet W5500芯片的以太网模块,是泥人电子继 Niren_W5100模块后设计的一块性能更好、性价比更高的以太网模块。

二、使用测试工具调试

使用TCP&UDP测试工具进行调试。


讯享网

 三、实现应用层modbus、httpd(web服务)协议编程

1.modbus协议编程

main函数:

 2.web协议编程

引脚初始化:

void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO , ENABLE); // Port A output GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1| GPIO_Pin_2 |GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); // GPIO_ResetBits(GPIOA, GPIO_Pin_0); // GPIO_ResetBits(GPIOA, GPIO_Pin_1); // GPIO_SetBits(GPIOA, GPIO_Pin_2); // led off // GPIO_SetBits(GPIOA, GPIO_Pin_3); // led off // Port B output; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_9); // Port C input // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;//控制flash GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_7); } 

讯享网

串口初始化:

讯享网void USART1_Init(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_USART1|RCC_APB2Periph_AFIO , ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // Configure the USART1_Rx as input floating GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IN_FLOATING ; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = ; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //Enable rx enable, /* Configure the USARTx */ USART_Init(USART1, &USART_InitStructure); /* Enable the USARTx */ USART_Cmd(USART1, ENABLE); } 

main函数:

int main(void) { Systick_Init(72); GPIO_Configuration(); //GPIO configuration USART1_Init(); //@8-n-1 printf("W5500 EVB initialization over.\r\n"); Reset_W5500(); WIZ_SPI_Init(); printf("W5500 initialized!\r\n"); if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7)) { DefaultSet();//出厂值 } else { get_config();//read config data from flash } printf("Firmware ver%d.%d\r\n",ConfigMsg.sw_ver[0],ConfigMsg.sw_ver[1]); if(ConfigMsg.debug==0) ConfigMsg.debug=1; set_network(); printf("Network is ready.\r\n"); while(1) { if(ConfigMsg.JTXD_Control == 0) do_http(); else JTXD_do_http(); if(reboot_flag) NVIC_SystemReset(); // reboot(); } } 

四、参考

STM32+W5500网络通信

基于STM32_DM9000_UIP_FreeModbus的Modbus-TCP功能实现工程下载

小讯
上一篇 2025-03-28 23:22
下一篇 2025-03-11 09:35

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/71941.html