单片机解密STM32F4+W5500以太网通讯
- 单片机解密/******************** (C) COPYRIGHT 2014 91mcu **************************
- 单片机解密* 文件名 :main.c
- 单片机解密* 描述 :W5500 以太网模块测试程序:Modbus-TCP 功能实现。
- 单片机解密* 实验平台:STM32F103VCT6+W5500
- 单片机解密* 库版本 :ST3.5.0
- *
- * 作者 :zhangsz
- **********************************************************************************/
- #include <string.h>
- #include <stdio.h>
- #include "stm32f10x.h"
- #include "W5500.h"
- #include "device.h"
- #include "systick.h"
- #include "led.h"
- #include "mb.h"
- /* ----------------------- Holding register Defines ------------------------------------------*/
- #define REG_HOLDING_START 1000
- #define REG_HOLDING_NREGS 4
- /* ----------------------- Static variables ---------------------------------*/
- static unsigned short usRegHoldingStart = REG_HOLDING_START;
- static unsigned short usRegHoldingBuf[REG_HOLDING_NREGS]={0xaa,0x55,0x5599,0x5588};
- /* ----------------------- input register Defines ------------------------------------------*/
- #define REG_INPUT_START 1000
- #define REG_INPUT_NREGS 4
- /* ----------------------- Static variables ---------------------------------*/
- static unsigned short usRegInputStart = REG_INPUT_START;
- static unsigned short usRegInputBuf[REG_INPUT_NREGS]={0,0,0x5599,0x5588};
- /* ----------------------- coils register Defines ------------------------------------------*/
- #define REG_COILS_START 1000
- #define REG_COILS_SIZE 16
- /* ----------------------- Static variables ---------------------------------*/
- static unsigned char ucRegCoilsBuf[REG_COILS_SIZE / 8]={0xaa,0xfe}; //数量低于8个还需要验证一下,是否需要加1呢。
- /* ----------------------- discrete register Defines ------------------------------------------*/
- #define REG_DISC_START 1000
- #define REG_DISC_SIZE 16
- /* ----------------------- Static variables ---------------------------------*/
- static unsigned char ucRegDiscBuf[REG_DISC_SIZE / 8] = { 0x98, 0x6e }; //数量8的整数倍。
- void BSP_LED(void); //LED指示线圈操作
- /* W5500 configuration */
- void W5500_Configuration()
- {
- unsigned char array[6];
- GPIO_SetBits(GPIO_W5500_RST_PORT, GPIO_W5500_RST_Pin);
- Delay_ms(100); /*delay 100ms 使用systick 1ms时基的延时*/
- while((Read_1_Byte(PHYCFGR)&LINK)==0); /* Waiting for Ethernet Link */
- Write_1_Byte(MR, RST);
- Delay_ms(20); /*delay 20ms */
- /* Set Gateway IP as: 192.168.1.1 */
- array[0]=192;
- array[1]=168;
- array[2]=1;
- array[3]=1;
- Write_Bytes(GAR, array, 4);
- /* Set Subnet Mask as: 255.255.255.0 */
- array[0]=255;
- array[1]=255;
- array[2]=255;
- array[3]=0;
- Write_Bytes(SUBR, array, 4);
- /* Set MAC Address as: 0x48,0x53,0x00,0x57,0x55,0x00 */
- array[0]=0x48;
- array[1]=0x53;
- array[2]=0x00;
- array[3]=0x57;
- array[4]=0x55;
- array[5]=0x00;
- Write_Bytes(SHAR, array, 6);
- /* Set W5500 IP as: 192.168.1.128 */
- array[0]=192;
- array[1]=168;
- array[2]=1;
- array[3]=128;
- Write_Bytes(SIPR, array, 4);
- }