金牌会员
 
- 积分
- 1044
- 金钱
- 1044
- 注册时间
- 2018-5-21
- 在线时间
- 114 小时
|
5金钱
想实现的功能是,串口发送AT,收到OK后发送hello,否则一直发送AT程序如下:
#include "stm32f10x.h"
#include "delay.h"
#include "string.h"
#include "stdio.h"
char RxCounter;
char *RxBuffer;
void My_Uart_Init(){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);
USART_DeInit(USART1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
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(USART1, &USART_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
void Uart1_SendStr(char*SendBuf)
{
while(*SendBuf)
{
while((USART1->SR&0X40)==0){}
USART1->DR = (u8) *SendBuf;
SendBuf++;
}
}
int main(void)
{
char *p="hello";
char *strx;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
My_Uart_Init();
Uart1_SendStr("AT");
delay_ms(300);
strx=strstr(RxBuffer,(const char*)"OK");
while(strx==NULL)
{
*RxBuffer=NULL;
Uart1_SendStr("AT");
delay_ms(300);
strx=strstr(RxBuffer,(const char*)"OK");
}
//RxCounter=0;
*RxBuffer=NULL;
delay_ms(300);
Uart1_SendStr(p);
while(1);
}
void USART1_IRQHandler(void){
u16 res;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
//res=USART_ReceiveData(USART3);
//USART_SendData(USART3, res);
*RxBuffer++=USART_ReceiveData(USART1);
}
//Uart1_SendStr((char*)RxBuffer);
}
程序执行时发送一次AT后,便不再执行了,用串口调试助手发送OK给串口1也没用,什么原因?如何解决?
|
-
|