STM32驅(qū)動(dòng)W5100實(shí)現(xiàn)udp通信
掃描二維碼
隨時(shí)隨地手機(jī)看文章
環(huán)境:
主機(jī):WIN7
開發(fā)環(huán)境:MDK4.72
MCU:STM32F103ZE
源代碼:
驅(qū)動(dòng)層代碼:
drv_w5100.h
/*********************************************************************
*w5100驅(qū)動(dòng)層頭文件
*(c)copyright2013,jdh
*AllRightReserved
*文件名:drv_w5100.h
*程序員:jdh
*修改日期:2013/10/22
*2013/10/23
*2013/10/24
**********************************************************************/
/*********************************************************************
硬件連接說明
電路標(biāo)號(hào)單片機(jī)引腳特殊功能
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