C语言对stm32f103程序,STM32F103WIFI程序C语言
《STM32F103WIFI程序C語言》由會員分享,可在線閱讀,更多相關《STM32F103WIFI程序C語言(33頁珍藏版)》請在人人文庫網上搜索。
1、實用標準文案 AP模式 AP的SSID : AT+WAP=11BG,LAUVAN(SSID),CHI AP的KEY: : AT+WAKEY=WPA2PSK,AES,22222222 AP模式: AT+WMODE=AP AP 作服務器時的端口號:AT+NETP=TCP,SERVER,6000,192.168.1.56 AP 的IP及網關:AT+LANN=192.168.1.1,255.255.255.0 透傳模式: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 uin。
3、t16 UART3_TxEnd; volatile uint8 UART3_TxEmptyFlag; /發送緩沖區空標志 volatile uint8 UART3OverTime; /超時時間 volatile uint8 UART3OverFlag; /超時標志 volatile uint8 UART3RxCompTime; /串口接收完成時間 volatile uint8 UART3RxCompJudg; /串口接收完成判斷 volatile uint8 UART3RxCompFlag; /串口接收完成標志 volatile uint16 Uart3OverTime; /WIFI相關參數 。
4、volatile uint8 WifiStatus=0; volatile uint8 IsWifiBusy; volatile uint32 Channel_Timer_Limit;/限時器 精彩文檔實用標準文案 /volatile uint16 Dog_IsWifiBusy = DOG_ISGPRSBUSY; volatile uint16 Dog_IsWifiBusy = 0; volatile uint8 WifiSendBuf512; volatile uint8 WifiRecBuf512; volatile uint8 SetWifiParmFlag=0; volatile ui。
5、nt8 SetWifiUartParmFlag=0; volatile uint8 Send2BTime=0; volatile uint8 WifiOnLinkFlag=0; volatile uint8 WifiSendStartTime=0; volatile uint8 WifiHeartbeatno=0; /Wifi發送心跳次數 volatile uint8 WifiSendEnterNetFlag=0; /Wifi發送登錄幀標志i volatile uint8 WifiEtherNetFlag=0; / /* * Function name: STM_EVAL_USART3_Ini。
6、t * Descriptions: 串口3中斷服務函數 * input parameters: 無 * Output parameters: 無 * Returned value: 無 */ void STM_EVAL_USART3_Init(void) NVIC_InitTypeDef NVIC_InitStructure; /* Enable and set USART3 Interrupt to the 0 priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /嵌套優先級分組為1 NVIC_InitStructure.N。
7、VIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* * * 初始化客戶端WifiPortIOSet * */ void WifiIOInit(void) 精彩文檔實用標準文案 GPIO_InitTypeDef。
8、 GPIO_InitStructure; /RCC_AHB1PeriphClockCmd(RCC_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; /定義Reload輸出腳20140731 GPIO_Init(G。
9、PIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, Reload); 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 = ResetTn; /定義ResetTn輸出腳20140731 GPIO_Init(GPIOB, &GPIO_InitSt。
10、ructure); GPIO_SetBits(GPIOB, ResetTn); RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Pin = PWR_SW; /定義PWR_SW輸出腳20140731 GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_SetB。
11、its(GPIOA, PWR_SW); /* * 名 稱: USART3_Wifi() * 功 能: 初始化串口3 * 入口參數: * 出口參數: */ void USART3_Wifi(void) GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; /* config USART2 clock */ /RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3 | RCC_APB2Periph_GPIOB, 精彩文檔實用標準文案 ENABLE); RCC_APB2。
12、PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_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_InitStructur。
13、e.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure USART3 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_InitStruc。
14、ture.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.US。
15、ART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART3, &USART_InitStructure); /*使能串口3的發送和接收中斷*/ USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_Cmd(USART3, ENABLE); STM_EVAL_USART3_Init(); /中斷初始化 WifiIOInit(); /WIFI控制腳的初始化20140731 /* * Function name: USART3_IRQHandler * Descriptions: 串口3中。
16、斷服務函數 * input parameters: 無 * Output parameters: 無 * Returned value: 無 */ void USART3_IRQHandler(void) if(USART_GetITStatus(USART3,USART_IT_RXNE) != RESET) 精彩文檔實用標準文案 UART3RxCompJudg = VALID_FLAG; UART3RxCompTime = 0; Uart3OverTime = 0; if( UART3_RxFullFlag = 0) UART3_RxBufUART3_RxEnd+ = USART_Recei。
17、veData(USART3); /* 保存接收到的數據 */ if(UART3_RxEnd = UART3_RXBUF_SIZE) UART3_RxEnd = 0; if(UART3_RxEnd = UART3_RxHead) UART3_RxFullFlag = 1; UART3_RxEmptyFlag = 0; /USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); /* * Function name: HandleRFSendData * Descriptions: 發送多個字節數據 * input parameters: Buffer:發送數據。
18、存儲位置 * NByte:發送數據個數 * Output parameters: 無 * Returned value: 無 */ void HandleWifiSendData(unsigned char *buffer,int bufferlen) while(bufferlen=0) USART_SendData(USART3, *buffer+); /ResetWdog(); while (USART_GetFlagStatus(USART3, USART_FLAG_TC) = RESET); bufferlen-; /USART_Cmd(USART3, ENABLE); /* * 名。
19、 稱: HandleRFUartTimer() * 功 能: 處理讀UART1時間 * 入口參數: 精彩文檔實用標準文案 * 出口參數: */ void HandleWifiUartTimer(void) if(UART3RxCompJudg = VALID_FLAG) /接收是否完成判斷 if(+UART3RxCompTime = UART3_COMP_TIME) /判斷接收中斷之間超時 UART3RxCompTime = 0; UART3RxCompJudg = 0; UART3RxCompFlag = VALID_FLAG; /NoReDataTime =0; else Uart3Ove。
20、rTime+; /* * 名 稱: Uart3ReadBytes() * 功 能: 讀取串口2字符串 * 入口參數:*pBuf:讀取數據存儲區 * 出口參數: */ uint16 Uart3ReadBytes(uint8 *pBuf) uint16 nEnd = 0; uint16 Size = 0; if(UART3_RxEmptyFlag = 0) /串口0接收數據緩沖區不為空 nEnd = UART3_RxEnd; /中斷可能改變此值 UART3_RxFullFlag = 0; if(UART3_RxHead head Size = nEnd - UART3_RxHead; memcpy。
21、(pBuf,(uint8 *)&UART3_RxBuf0 + UART3_RxHead, Size); UART3_RxHead = nEnd; 精彩文檔實用標準文案 else /head end Size = 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,(uint8 *)&UAR。
22、T3_RxBuf0,nEnd); UART3_RxHead = nEnd; if(UART3_RxHead = UART3_RxEnd) UART3_RxEmptyFlag = 1; /接收數據緩沖區空 else Size = 0; memset(uint8*)&UART3_RxBuf0,0x00,512); return Size; /* * 名稱:GetWifiMode485Data() * 功能:讀出接收的數據,取出完整的一幀,放到接收BUF, * 入口參數:無 * 出口參數:返回長度和數據BUF。 */ uint16 GetWifiMode485Data(void) uint16 lo。
23、op,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; /錯誤格式信息 starti = i; /point 0x68 i += 7; 精彩文檔實用標準文案 if(WifiRecBufi!=0x68) return 0; i+; /poin。
24、t ctrlcode i+; /point len; temp1= WifiRecBufi; temp2= WifiRecBufi+1; datalen = (uint16)(temp1 + temp2*256); /2013-09-05 i += 2; if(i+datalen = temps) return 0; i += datalen; /point cs i+; /point 0x16 if(WifiRecBufi != 0x16) return 0; size = datalen + 9; /head(9) + cs + 0x16 for(loop=0;loop2) Channel。
25、_Timer_Limit=100; Send2BTime=0; else Channel_Timer_Limit=10; break; case Wifi_A: /再發a WifiSendBuf0=0x61; HandleWifiSendData(uint8*)&WifiSendBuf0, 1); Channel_Timer_Limit=100; break; default: /開始發AT指令 WifiATFrame(WifiStatus); Channel_Timer_Limit=100; break; /處理Wifi 串口模式 else if(SetWifiUartParmFlag=VALID_FLAG)&(Channel_Timer_Limit=0) GPIO_SetBits(GPIOB, ResetTn); switch(WifiStatus) case Wifi_INIT: /先發+ if(WifiSendStartTime5)。
總結
以上是生活随笔為你收集整理的C语言对stm32f103程序,STM32F103WIFI程序C语言的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux修改hostname
- 下一篇: 人民币读法的java程序_Java浮点数