STM32F103 WIFI初始化流程STA模式.docx

上传人:b****5 文档编号:6142330 上传时间:2023-01-04 格式:DOCX 页数:37 大小:23.31KB
下载 相关 举报
STM32F103 WIFI初始化流程STA模式.docx_第1页
第1页 / 共37页
STM32F103 WIFI初始化流程STA模式.docx_第2页
第2页 / 共37页
STM32F103 WIFI初始化流程STA模式.docx_第3页
第3页 / 共37页
STM32F103 WIFI初始化流程STA模式.docx_第4页
第4页 / 共37页
STM32F103 WIFI初始化流程STA模式.docx_第5页
第5页 / 共37页
点击查看更多>>
下载资源
资源描述

STM32F103 WIFI初始化流程STA模式.docx

《STM32F103 WIFI初始化流程STA模式.docx》由会员分享,可在线阅读,更多相关《STM32F103 WIFI初始化流程STA模式.docx(37页珍藏版)》请在冰豆网上搜索。

STM32F103 WIFI初始化流程STA模式.docx

STM32F103WIFI初始化流程STA模式

STA模式

STA的SSID:

AT+WSSSID=1LAUVAN

STA的KEY:

:

AT+WSKEY=WPAPSK,AES,pxfpxfpxf默认

STA模式:

AT+WMODE=STA

STA作服务器时的端口号:

AT+NETP=TCP,SERVER,6000,192.168.1.56

STA的IP及网关:

AT+WANN=DHCP,192.168.1.35,255.255.255.0,192.168.1.1默认

STA模式下MAC的设置:

AT+WSMAC=8888,123456789ABC

透传模式:

AT+ENTM

串口模式:

/*****************************************************************************************************

名称:

变量定义

*****************************************************************************************************/

volatileuint8UART3_RxBuf[UART3_RXBUF_SIZE];

volatileuint8UART3_TxBuf[UART3_TXBUF_SIZE];

volatileuint8UART3RxFlag;//接收标志

volatileuint16UART3_RxHead;//接收缓冲区读指针

volatileuint16UART3_RxEnd;//接收缓冲区指针

volatileuint8UART3_RxFullFlag;//接收缓冲区满标志

volatileuint8UART3_RxEmptyFlag;//接收缓冲区空标志

volatileuint8UART3TxFlag;//发送标志

volatileuint16UART3_TxHead;

volatileuint16UART3_TxEnd;

volatileuint8UART3_TxEmptyFlag;//发送缓冲区空标志

volatileuint8UART3OverTime;//超时时间

volatileuint8UART3OverFlag;//超时标志

volatileuint8UART3RxCompTime;//串口接收完成时间

volatileuint8UART3RxCompJudg;//串口接收完成判断

volatileuint8UART3RxCompFlag;//串口接收完成标志

volatileuint16Uart3OverTime;

 

//WIFI相关参数

volatileuint8WifiStatus=0;

volatileuint8IsWifiBusy;

volatileuint32Channel_Timer_Limit;//限时器

//volatileuint16Dog_IsWifiBusy=DOG_ISGPRSBUSY;

volatileuint16Dog_IsWifiBusy=0;

volatileuint8WifiSendBuf[512];

volatileuint8WifiRecBuf[512];

volatileuint8SetWifiParmFlag=0;

volatileuint8SetWifiUartParmFlag=0;

volatileuint8Send2BTime=0;

volatileuint8WifiOnLinkFlag=0;

volatileuint8WifiSendStartTime=0;

volatileuint8WifiHeartbeatno=0;//Wifi发送心跳次数

volatileuint8WifiSendEnterNetFlag=0;//Wifi发送登录帧标志i

volatileuint8WifiEtherNetFlag=0;//

/***************************************************************************************************

**Functionname:

STM_EVAL_USART3_Init

**Descriptions:

串口3中断服务函数

**inputparameters:

**Outputparameters:

:

**Returnedvalue:

****************************************************************************************************/

voidSTM_EVAL_USART3_Init(void)

{

NVIC_InitTypeDefNVIC_InitStructure;

/*EnableandsetUSART3Interrupttothe0priority*/

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//嵌套优先级分组为1

NVIC_InitStructure.NVIC_IRQChannel=USART3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;

NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;

NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;

NVIC_Init(&NVIC_InitStructure);

}

/*****************************************************************************************************

**

**初始化客户端WifiPortIOSet

**

*****************************************************************************************************/

voidWifiIOInit(void)

{

GPIO_InitTypeDefGPIO_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(GPIOB,&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_InitStructure);

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_SetBits(GPIOA,PWR_SW);

}

/****************************************************************************************************

*名称:

USART3_Wifi()

*功能:

初始化串口3

*入口参数:

*出口参数:

******************************************************************************************************/

voidUSART3_Wifi(void)

{

GPIO_InitTypeDefGPIO_InitStructure;

USART_InitTypeDefUSART_InitStructure;

/*configUSART2clock*/

//RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3|RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);

/*USART3GPIOconfig*/

/*ConfigureUSART3Tx(PB.10)asalternatefunctionpush-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);

/*ConfigureUSART3Rx(PB.11)asinputfloating*/

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB,&GPIO_InitStructure);

/*USART3modeconfig*/

USART_InitStructure.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.USART_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

}

/*********************************************************************************************************

**Functionname:

USART3_IRQHandler

**Descriptions:

串口3中断服务函数

**inputparameters:

**Outputparameters:

:

**Returnedvalue:

*********************************************************************************************************/

voidUSART3_IRQHandler(void)

{

if(USART_GetITStatus(USART3,USART_IT_RXNE)!

=RESET)

{

UART3RxCompJudg=VALID_FLAG;

UART3RxCompTime=0;

Uart3OverTime=0;

if(UART3_RxFullFlag==0)

{

UART3_RxBuf[UART3_RxEnd++]=USART_ReceiveData(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);

}

/*********************************************************************************************************

**Functionname:

HandleRFSendData

**Descriptions:

发送多个字节数据

**inputparameters:

Buffer:

发送数据存储位置

**NByte:

发送数据个数

**Outputparameters:

:

**Returnedvalue:

*********************************************************************************************************/

voidHandleWifiSendData(unsignedchar*buffer,intbufferlen)

{

while(bufferlen>=0)

{

USART_SendData(USART3,*buffer++);

//ResetWdog();

while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET);

bufferlen--;

}

//USART_Cmd(USART3,ENABLE);

}

/********************************************************************************************

*名称:

HandleRFUartTimer()

*功能:

处理读UART1时间

*入口参数:

*出口参数:

*********************************************************************************************/

voidHandleWifiUartTimer(void)

{

if(UART3RxCompJudg==VALID_FLAG)//接收是否完成判断

{

if(++UART3RxCompTime>=UART3_COMP_TIME)//判断接收中断之间超时

{

UART3RxCompTime=0;

UART3RxCompJudg=0;

UART3RxCompFlag=VALID_FLAG;

}

//NoReDataTime=0;

}

else

Uart3OverTime++;

}

/***********************************************************************************************

*名称:

Uart3ReadBytes()

*功能:

读取串口2字符串

*入口参数:

*pBuf:

读取数据存储区

*出口参数:

*************************************************************************************************/

uint16Uart3ReadBytes(uint8*pBuf)

{

uint16nEnd=0;

uint16Size=0;

if(UART3_RxEmptyFlag==0)//串口0接收数据缓冲区不为空

{

nEnd=UART3_RxEnd;//中断可能改变此值

UART3_RxFullFlag=0;

if(UART3_RxHeadhead

{

Size=nEnd-UART3_RxHead;

memcpy(pBuf,(uint8*)&UART3_RxBuf[0]+UART3_RxHead,Size);

UART3_RxHead=nEnd;

}

else//head>end

{

Size=UART3_RXBUF_SIZE+nEnd-UART3_RxHead;

memcpy(pBuf,(uint8*)&UART3_RxBuf[0]+UART3_RxHead,UART3_RXBUF_SIZE-UART3_RxHead);

if(nEnd>0)

memcpy(pBuf+UART3_RXBUF_SIZE-UART3_RxHead,(uint8*)&UART3_RxBuf[0],nEnd);

UART3_RxHead=nEnd;

}

if(UART3_RxHead==UART3_RxEnd)

UART3_RxEmptyFlag=1;//接收数据缓冲区空

}

else

Size=0;

memset((uint8*)&UART3_RxBuf[0],0x00,512);

returnSize;

}

/************************************************************************************************

*名称:

GetWifiMode485Data()

*功能:

读出接收的数据,取出完整的一帧,放到接收BUF,

*入口参数:

*出口参数:

返回长度和数据BUF。

**************************************************************************************************/

uint16GetWifiMode485Data(void)

{

uint16loop,temps,size;

uint16i,starti;

uint8temp1,temp2;

uint16datalen;

memset((uint8*)&WifiRecBuf,0x00,512);

size=Uart3ReadBytes((uint8*)WifiRecBuf);

temps=size;

i=0;

while(WifiRecBuf[i]!

=0x68&&i

i++;

if(i>=size)

return0;//错误格式信息

starti=i;//point0x68

i+=7;

if(WifiRecBuf[i]!

=0x68)

return0;

i++;//pointctrlcode

i++;//pointlen;

temp1=WifiRecBuf[i];

temp2=WifiRecBuf[i+1];

datalen=(uint16)(temp1+temp2*256);//2013-09-05

i+=2;

if(i+datalen>=temps)

return0;

i+=datalen;//pointcs

i++;//point0x16

if(WifiRecBuf[i]!

=0x16)

return0;

size=datalen+9;//head(9)+cs+0x16

for(loop=0;loop

WifiRecBuf[loop]=WifiRecBuf[loop+starti];

returnsize;

}

/************************************************************************************************

*名称:

GetWifiATData()

*功能:

读出接收的数据,取出完整的一帧,放到接收BUF,

*入口参数:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1