《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)。