STM32F103WIFI程序C語(yǔ)言_第1頁(yè)
STM32F103WIFI程序C語(yǔ)言_第2頁(yè)
STM32F103WIFI程序C語(yǔ)言_第3頁(yè)
STM32F103WIFI程序C語(yǔ)言_第4頁(yè)
STM32F103WIFI程序C語(yǔ)言_第5頁(yè)
已閱讀5頁(yè),還剩17頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、實(shí)用標(biāo)準(zhǔn)文案AP模式AP 的 SSID : AT+WAP=11BG,LAUVAN(SSID),CHIAP 的 KEY: : AT+WAKEY=WPA2PSK,AES,22222222AP 模式: AT+WMODE=APAP 作服務(wù)器時(shí)的端口號(hào): AT+NETP=TCP,SERVER,6000,192.168.1.56AP 的 IP 及網(wǎng)關(guān): AT+LANN=192.168.1.1,255.255.255.0 透?jìng)髂J剑?AT+ENTM串口模式:/*名稱 : 變量定義*/volatile uint8 UART3_RxBufUART3_RXBUF_SIZE; volatile uint8 UART

2、3_TxBufUART3_TXBUF_SIZE;volatile uint8 UART3RxFlag;volatile uint16 UART3_RxHead; volatile uint16 UART3_RxEnd;volatile uint8 UART3_RxFullFlag; volatile uint8 UART3_RxEmptyFlag;volatile uint8 UART3TxFlag;volatile uint16 UART3_TxHead;volatile uint16 UART3_TxEnd;volatile uint8 UART3_TxEmptyFlag;volatile

3、 uint8 UART3OverTime;volatile uint8 UART3OverFlag;volatile uint8 UART3RxCompTime; volatile uint8 UART3RxCompJudg;volatile uint8 UART3RxCompFlag;/ 接收標(biāo)志/ 接收緩沖區(qū)讀指針/ 接收緩沖區(qū)指針/ 接收緩沖區(qū)滿標(biāo)志/ 接收緩沖區(qū)空標(biāo)志/ 發(fā)送標(biāo)志/ 發(fā)送緩沖區(qū)空標(biāo)志/ 超時(shí)時(shí)間/ 超時(shí)標(biāo)志/ 串口接收完成時(shí)間/ 串口接收完成判斷/ 串口接收完成標(biāo)志volatile uint16 Uart3OverTime;/WIFI 相關(guān)參數(shù)volatile uint

4、8 WifiStatus=0;volatile uint8 IsWifiBusy;volatile uint32 Channel_Timer_Limit;/限時(shí)器精彩文檔實(shí)用標(biāo)準(zhǔn)文案/volatile uint16 Dog_IsWifiBusy = DOG_ISGPRSBUSY;volatile uint16 Dog_IsWifiBusy = 0;volatile uint8 WifiSendBuf512;volatile uint8 WifiRecBuf512;volatile uint8 SetWifiParmFlag=0;volatile uint8 SetWifiUartParmFla

5、g=0;volatile uint8 Send2BTime=0;volatile uint8 WifiOnLinkFlag=0;volatile uint8 WifiSendStartTime=0;volatile uint8 WifiHeartbeatno=0; /Wifi 發(fā)送心跳次數(shù)volatile uint8 WifiSendEnterNetFlag=0; /Wifi發(fā)送登錄幀標(biāo)志 ivolatile uint8 WifiEtherNetFlag=0; / /* Function name:* Descriptions:* input parameters:* Output param

6、eters:* Returned value:STM_EVAL_USART3_Init串口 3 中斷服務(wù)函數(shù) 無(wú)無(wú)無(wú)*/void STM_EVAL_USART3_Init(void)NVIC_InitTypeDef NVIC_InitStructure;嵌套優(yōu)先級(jí)分組為 1/* Enable and set USART3 Interrupt to the 0 priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); / NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_In

7、itStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);* 初始化客戶端 WifiPortIOSet*/ void WifiIOInit(void) 精彩文檔實(shí)用標(biāo)準(zhǔn)文案GPIO_InitTypeDef GPIO_InitStructure;/RCC_AHB1PeriphClockCmd(RCC

8、_AHB1Periph_GPIOB , ENABLE);RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_InitStructure.GPIO_Pin= Reload;/20140731GPIO_Init(GPIOB, &GPIO_InitStructure);GPIO_SetBits(GPIOB, Reload);RCC_APB2Per

9、iphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_InitStructure.GPIO_Pin = ResetTn; / 腳 20140731定義 Reload 輸出腳定義 ResetTn 輸出GPIO_Init(GPIOB, &GPIO_InitStructure);GPIO_SetBits(GPIOB, ResetTn);RCC_APB2PeriphClo

10、ckCmd( RCC_APB2Periph_GPIOA, ENABLE);GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Pin20140731= PWR_SW;/定義 PWR_SW輸出腳GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_SetBits(GPIOA, PWR_SW);/* 名稱: USART3_Wifi()* 功能: 初始化串口 3* 入口參數(shù):* 出口

11、參數(shù):*/void USART3_Wifi(void)GPIO_InitTypeDef GPIO_InitStructure;USART_InitTypeDef USART_InitStructure;/* config USART2 clock */RCC_APB2Periph_GPIOB,/RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3 |精彩文檔實(shí)用標(biāo)準(zhǔn)文案ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);RCC_APB1PeriphClockCmd(RCC_APB1Peri

12、ph_USART3, ENABLE);/* USART3 GPIO config */* Configure USART3 Tx (PB.10) as alternate function push-pull */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure);/* Configure USAR

13、T3 Rx (PB.11) as input floating */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOB, &GPIO_InitStructure);/* USART3 mode config */USART_InitStructure.USART_BaudRate = 115200;USART_InitStructure.USART_WordLength = USART_WordLength_8b;USART_

14、InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_Parity = USART_Parity_No ;USART_InitStructure.USART_HardwareFlowControlUSART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;USART_Init(USART3, &USART_InitStructure);/* 使能串口 3 的發(fā)送和接收中斷 *

15、/USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);USART_Cmd(USART3, ENABLE);STM_EVAL_USART3_Init(); / 中斷初始化WifiIOInit(); /WIFI 控制腳的初始化 20140731/* Function name:* Descriptions:* input parameters:* Output parameters:* Returned value:USART3_IRQHandler串口 3 中斷服務(wù)函數(shù) 無(wú)無(wú)無(wú)*/void USART3_IRQHandler(void) if(USART_

16、GetITStatus(USART3,USART_IT_RXNE) != RESET)精彩文檔實(shí)用標(biāo)準(zhǔn)文案UART3RxCompJudg = VALID_FLAG;UART3RxCompTime = 0;Uart3OverTime = 0;if( UART3_RxFullFlag = 0)UART3_RxBufUART3_RxEnd+ = USART_ReceiveData(USART3); /* 存接收到的數(shù)據(jù) */if(UART3_RxEnd = UART3_RXBUF_SIZE) UART3_RxEnd = 0;if(UART3_RxEnd = UART3_RxHead) UART3_R

17、xFullFlag = 1;UART3_RxEmptyFlag = 0;/USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);/* Function name:HandleRFSendData發(fā)送多個(gè)字節(jié)數(shù)據(jù)發(fā)送數(shù)據(jù)存儲(chǔ)位置 發(fā)送數(shù)據(jù)個(gè)數(shù) 無(wú)* Descriptions:* input parameters: Buffer:* NByte:* Output parameters:* Returned value:*/void HandleWifiSendData(unsigned char *buffer,int bufferlen) while(buf

18、ferlen=0)USART_SendData(USART3, *buffer+);/ResetWdog();while (USART_GetFlagStatus(USART3, USART_FLAG_TC) = RESET); bufferlen-;/USART_Cmd(USART3, ENABLE);/* 名 稱: HandleRFUartTimer()* 功 能: 處理讀 UART1時(shí)間* 入口參數(shù):精彩文檔實(shí)用標(biāo)準(zhǔn)文案* 出口參數(shù):*/void HandleWifiUartTimer(void)if(UART3RxCompJudg = VALID_FLAG) / 接收是否完成判斷 if

19、(+UART3RxCompTime = UART3_COMP_TIME) / 判斷接收中斷之間超時(shí) UART3RxCompTime = 0;UART3RxCompJudg = 0; UART3RxCompFlag = VALID_FLAG;/NoReDataTime =0; elseUart3OverTime+;/* 名稱: Uart3ReadBytes()* 功能: 讀取串口 2 字符串* 入口參數(shù): *pBuf: 讀取數(shù)據(jù)存儲(chǔ)區(qū)* 出口參數(shù):uint16 Uart3ReadBytes(uint8 *pBuf) uint16 nEnd = 0;uint16 Size = 0;/ 串口 0 接

20、收數(shù)據(jù)緩沖區(qū)不為空/ 中斷可能改變此值/end headif(UART3_RxEmptyFlag = 0) nEnd = UART3_RxEnd;UART3_RxFullFlag = 0;if(UART3_RxHead endSize = UART3_RXBUF_SIZE + nEnd - UART3_RxHead;memcpy(pBuf,(uint8 *)&UART3_RxBuf0 + UART3_RxHead,UART3_RXBUF_SIZE - UART3_RxHead);if(nEnd 0)memcpy(pBuf + UART3_RXBUF_SIZE - UART3_RxHead,(u

21、int8 *)&UART3_RxBuf0,nEnd);UART3_RxHead = nEnd;if(UART3_RxHead = UART3_RxEnd)UART3_RxEmptyFlag = 1;/ 接收數(shù)據(jù)緩沖區(qū)空elseSize = 0;memset(uint8*)&UART3_RxBuf0,0x00,512);return Size;/* 名稱: GetWifiMode485Data()* 功能:讀出接收的數(shù)據(jù),取出完整的一幀,放到接收BUF,* 入口參數(shù):無(wú)* 出口參數(shù):返回長(zhǎng)度和數(shù)據(jù) BUF。*/uint16 GetWifiMode485Data(void)uint16 loop,

22、temps,size;uint16 i,starti;uint8 temp1,temp2;uint16 datalen;memset(uint8*)&WifiRecBuf,0x00,512);size= Uart3ReadBytes(uint8*)WifiRecBuf);temps = size;i=0;while(WifiRecBufi!=0x68 & i=size)return 0;/ 錯(cuò)誤格式信息starti = i;/point 0x68i += 7;精彩文檔實(shí)用標(biāo)準(zhǔn)文案if(WifiRecBufi!=0x68)return 0;i+;/point ctrlcodei+;/point

23、len;temp1= WifiRecBufi;temp2= WifiRecBufi+1;/2013-09-05datalen = (uint16)(temp1 + temp2*256); i += 2;if(i+datalen = temps)return 0;i += datalen;/point csi+;/point 0x16if(WifiRecBufi != 0x16) return 0;size = datalen + 9; /head(9) + cs + 0x16 for(loop=0;loop2) Channel_Timer_Limit=100;Send2BTime=0;else

24、Channel_Timer_Limit=10;break;case Wifi_A: / 再發(fā) a WifiSendBuf0=0x61; HandleWifiSendData(uint8*)&WifiSendBuf0, 1);Channel_Timer_Limit=100;break;default: / 開始發(fā) AT 指令WifiATFrame(WifiStatus);Channel_Timer_Limit=100;break;/ 處理 Wifi 串口模式else if(SetWifiUartParmFlag=VALID_FLAG)&(Channel_Timer_Limit=0) GPIO_S

25、etBits(GPIOB, ResetTn);switch(WifiStatus)case Wifi_INIT: /先發(fā) +if(WifiSendStartTime5)/ SendGprsEnterFrame(3);WifiSendStartTime=0; Channel_Timer_Limit=200; WifiSendEnterNetFlag=VALID_FLAG;精彩文檔實(shí)用標(biāo)準(zhǔn)文案break;WifiSendEnterNetFlag=0;memset(uint8*)&WifiSendBuf0,0x2b,3);HandleWifiSendData(uint8*)WifiSendBuf,

26、1);Send2BTime+;if(Send2BTime2)Channel_Timer_Limit=100;Send2BTime=0;WifiSendStartTime+;elseChannel_Timer_Limit=10;break;case Wifi_A:/ 再發(fā) aif(WifiSendStartTime5)/SendGprsEnterFrame(3);WifiSendStartTime=0;Channel_Timer_Limit=200;WifiSendEnterNetFlag=VALID_FLAG;break;WifiSendBuf0=0x61;HandleWifiSendData

27、(uint8*)WifiSendBuf, 1);Channel_Timer_Limit=100;WifiSendStartTime+;break;default: / 開始發(fā) AT 指令WifiATFrame(WifiStatus);Channel_Timer_Limit=50;break;/Channel_Timer_Limit=100;/* 名稱: HandleWifiData()* 功能:處理上行串口接收到的數(shù)據(jù)精彩文檔實(shí)用標(biāo)準(zhǔn)文案* 入口參數(shù):* 出口參數(shù):*/void HandleWifiData(void)uint16 DataLen;GprsFrameType *pLCFrame

28、;if(SetWifiParmFlag=VALID_FLAG & WifiSendEnterNetFlag!=VALID_FLAG)DataLen = GetWifiATData();switch(WifiStatus)case Wifi_INIT:if(WifiRecBuf0=0x61)WifiStatus=Wifi_A;break;case Wifi_A:if(WifiRecBuf0=0x2b&WifiRecBuf1=0x6f&WifiRecBuf2=0x6b)if(SetWifiParmFlag!=0)WifiStatus=Wifi_STA;elseWifiStatus=Wifi_WSL

29、K;break;case Wifi_STA:if(WifiRecBuf0=0x2b&WifiRecBuf1=0x6f&WifiRecBuf2=0x6b)WifiStatus=Wifi_WSSSID;Channel_Timer_Limit=0;break;case Wifi_WSSSID:if(WifiRecBuf0=0x2b&WifiRecBuf1=0x6f&WifiRecBuf2=0x6b)WifiStatus=Wifi_WSKEY;Channel_Timer_Limit=0;break;case Wifi_WSKEY:if(WifiRecBuf0=0x2b&WifiRecBuf1=0x6f&WifiRecBuf2=0x6b)WifiStatus=Wifi_WANN;精彩文檔實(shí)用標(biāo)準(zhǔn)文案Channel_Timer_Limit=0; break;case Wifi_WANN:if(WifiRecBuf0=0x2b

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論