STM32驱动W5100实现udp通信
扫描二维码
随时随地手机看文章
环境:
主机:WIN7
开发环境:MDK4.72
MCU:STM32F103ZE
源代码:
驱动层代码:
drv_w5100.h
/*********************************************************************
*w5100驱动层头文件
*(c)copyright2013,jdh
*AllRightReserved
*文件名:drv_w5100.h
*程序员:jdh
*修改日期:2013/10/22
*2013/10/23
*2013/10/24
**********************************************************************/
/*********************************************************************
硬件连接说明
电路标号单片机引脚特殊功能
W5100_MISOPB4SPI3_MISO
W5100_MOSIPB5SPI3_MOSI
W5100_CSPA15SPI3_NSS
W5100_SCLKPB3SPI3_SCK
/RESETPD3
/INTPD6
**********************************************************************/
#ifndef_DRV_W5100_H_
#define_DRV_W5100_H_
/*********************************************************************
*头文件
**********************************************************************/
#include"stm32f10x.h"
#include"stm32f10x_spi.h"
/*********************************************************************
*宏定义
**********************************************************************/
/*********************************************************************
*读写操作
**********************************************************************/
//写操作
#defineWRITE_COMMAND0xf0
//读操作
#defineREAD_COMMAND0x0f
/*********************************************************************
*基地址
**********************************************************************/
#defineCOMMON_BASE0x0000
/*********************************************************************
*寄存器
**********************************************************************/
//-----------------------------------------------------------------------------
//Commonregister
//-----------------------------------------------------------------------------
//Moderegister,R/W,Default=0x00
#defineSOCKET00
#defineSOCKET11
#defineSOCKET22
#defineSOCKET33
#defineTCP_SERVER0
#defineTCP_CLIENT1
#defineUDP2
#defineW5100_MODECOMMON_BASE
#defineMODE_RST0x80//Softwarereset
#defineMODE_PB0x10//Pingblockmode
#defineMODE_PPPOE0x08//PPOEmode
#defineMODE_AI0x02//AddressautoincrementinindirectbusI/F
#defineMODE_IND0x01//IndirectbusI/Fmode
//Gatewayaddressregister,R/W,default=0x00
#defineW5100_GARCOMMON_BASE+0x01
//Subnetmaskaddress,R/W,default=0x00
#defineW5100_SUBRCOMMON_BASE+0x05
//Sourcehardwareaddress,R/W,default=0x00
#defineW5100_SHARCOMMON_BASE+0x09
//SourceIPaddress,R/W,default=0x00
#defineW5100_SIPRCOMMON_BASE+0x0f
//Interruptandinterruptmaskregister
#defineW5100_IRCOMMON_BASE+0x15//RO,Default=0x00
#defineIR_CONFLICT0x80//IPconflict
#defineIR_UNREACH0x40//Destinationunreachable
#defineIR_PPPOE0x20//PPOEclose
#defineIR_S3_INT0x08//Occurrenceofsocket3socketinterrupt
#defineIR_S2_INT0x04//Occurrenceofsocket2socketinterrupt
#defineIR_S1_INT0x02//Occurrenceofsocket1socketinterrupt
#defineIR_S0_INT0x01//Occurrenceofsocket0socketinterrupt
#defineW5100_IMRCOMMON_BASE+0x16//R/W,Default=0x00
#defineIMR_CONFLICT0x80//IPconflict
#defineIMR_UNREACH0x40//Destinationunreachable
#defineIMR_PPPOE0x20//PPOEclose
#defineIMR_S3_INT0x08//Occurrenceofsocket3socketinterrupt
#defineIMR_S2_INT0x04//Occurrenceofsocket2socketinterrupt
#defineIMR_S1_INT0x02//Occurrenceofsocket1socketinterrupt
#define IMR_S0_INT 0x01 //Occurrence of socket 0 socket interrupt