STM32温湿度传感器检测,W5500以太网发送程序
- #include "stm32f10x.h"
- #include "stm32f10x_spi.h"
- #include "W5500.h"
- #include "delay.h"
- /***************----- 网络参数变量定义 -----***************/
- unsigned char Gateway_IP[4];//网关IP地址
- unsigned char Sub_Mask[4]; //子网掩码
- unsigned char Phy_Addr[6]; //物理地址(MAC)
- unsigned char IP_Addr[4]; //本机IP地址
- unsigned char S0_Port[2]; //端口0的端口号(5000)
- unsigned char S0_DIP[4]; //端口0目的IP地址
- unsigned char S0_DPort[2]; //端口0目的端口号(6000)
- unsigned char UDP_DIPR[4]; //UDP(广播)模式,目的主机IP地址
- unsigned char UDP_DPORT[2]; //UDP(广播)模式,目的主机端口号
- /***************----- 端口的运行模式 -----***************/
- unsigned char S0_Mode =3; //端口0的运行模式,0:TCP服务器模式,1:TCP客户端模式,2:UDP(广播)模式
- #define TCP_SERVER 0x00 //TCP服务器模式
- #define TCP_CLIENT 0x01 //TCP客户端模式
- #define UDP_MODE 0x02 //UDP(广播)模式
- /***************----- 端口的运行状态 -----***************/
- unsigned char S0_State =0; //端口0状态记录,1:端口完成初始化,2端口完成连接(可以正常传输数据)
- #define S_INIT 0x01 //端口完成初始化
- #define S_CONN 0x02 //端口完成连接,可以正常传输数据
- /***************----- 端口收发数据的状态 -----***************/
- unsigned char S0_Data; //端口0接收和发送数据的状态,1:端口接收到数据,2:端口发送数据完成
- #define S_RECEIVE 0x01 //端口接收到一个数据包
- #define S_TRANSMITOK 0x02 //端口发送一个数据包完成
- /***************----- 端口数据缓冲区 -----***************/
- unsigned char Rx_Buffer[2048]; //端口接收数据缓冲区
- unsigned char Tx_Buffer[2048]; //端口发送数据缓冲区
- unsigned char W5500_Interrupt; //W5500中断标志(0:无中断,1:有中断)
- /*******************************************************************************
- * 函数名 : W5500_GPIO_Configuration
- * 描述 : W5500 GPIO初始化配置
- * 输入 : 无
- * 输出 : 无
- * 返回值 : 无
- * 说明 : 无
- *******************************************************************************/
- void W5500_GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- /* W5500_RST引脚初始化配置(PC5) */
- GPIO_InitStructure.GPIO_Pin = W5500_RST; //pin 5
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz; //速率10MHZ
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
- GPIO_Init(W5500_RST_PORT, &GPIO_InitStructure); //PC
- GPIO_ResetBits(W5500_RST_PORT, W5500_RST); //默认PC5置低
-
- /* W5500_INT引脚初始化配置(PC4) */
- GPIO_InitStructure.GPIO_Pin = W5500_INT;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(W5500_INT_PORT, &GPIO_InitStructure);
-
- /* Connect EXTI Line4 to PC4 */
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource4);
- /* PC4 as W5500 interrupt input */
- EXTI_InitStructure.EXTI_Line = EXTI_Line4;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }

芯片解密