新手上路
- 积分
- 26
- 金钱
- 26
- 注册时间
- 2015-8-17
- 在线时间
- 0 小时
|
5金钱
求助!!最近在玩gsm模块,为什么我的单片机识别不了我的短信内容
程序是实现接到短信点亮一个灯,并返回一条短信,但单片机就是收不到短信啊,求指导是为什么
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "math.h"
#include "string.h"
struct __FILE
{
int handle;
};
FILE __stdout;
_sys_exit(int x)
{
x = x;
}
int fputc(int ch, FILE *f)
{
while((USART6->SR&0X40)==0);
USART6->DR = (u8) ch;
return ch;
}
int fgetc(FILE *f)
{
while (USART_GetFlagStatus(USART6, USART_FLAG_RXNE) == RESET);
return (int)USART_ReceiveData(USART6);
}
#endif
#if EN_USART6_RX
u8 USART_RX_BUF[USART_REC_LEN];
u16 USART_RX_STA=0;
void UART6_Send_Str(unsigned char *s)//????? ?? ???? ??
{
unsigned char i=0;
while(s!='\0')
{
USART_SendData(USART1,s);
while( USART_GetFlagStatus(USART1,USART_FLAG_TC)!= SET);
i++;
}
}
void RECEIVE_SMS()
{
u8 i;
printf("AT+CNMI=2,1\r\n");
delay_ms(100);
printf("AT+CMGF=1\r\n");
delay_ms(100);
printf("AT+CSCS=\"GSM\"\r\n");
delay_ms(100);
printf("AT+CMGR=1\r\n");
delay_ms(500);
for(i=0;i<200;i++)
{
if(USART_RX_BUF==0x61)
{
delay_ms(200);
GPIO_SetBits(GPIOA,GPIO_Pin_5);
delay_ms(200);
printf("AT+CMGF=1\r\n");
delay_ms(200);
printf("AT+CSCA?\r\n");
delay_ms(200);
printf("AT+CSMP=17,167,0,25\r\n");
delay_ms(200);
printf("AT+CSCS=\"UCS2\"\r\n");
delay_ms(200);
printf("AT+CMGS=\"00310035003700330036003700300039003800360036\"\r\n");
delay_ms(200);//??3?
printf("60A867E58BE2768482B176C600316E7F5EA64E3A\r\n");
delay_ms(500);
printf("\x1a");
delay_ms(200);//??20? 31 41 0D 0A
}
}
}
void uart_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_USART6);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_USART6);
//USART1????????
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
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(USART6, &USART_InitStructure);
USART_Cmd(USART6, ENABLE);
USART_ClearFlag(USART6, USART_FLAG_TC);
#if EN_USART6_RX
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
}
void USART6_IRQHandler(void)
{
u8 Res;
#ifdef OS_TICKS_PER_SEC
OSIntEnter();
#endif
if(USART_GetITStatus(USART6, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(USART6);
if((USART_RX_STA&0x8000)==0)
{
if(USART_RX_STA&0x4000)
{
if(Res!=0x0a)USART_RX_STA=0;
else USART_RX_STA|=0x8000;
}
else
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;
}
}
}
RECEIVE_SMS();
USART_ClearITPendingBit(USART6,USART_IT_RXNE);
#ifdef OS_TICKS_PER_SEC //?????±?????????¨????,???÷??????ucosII??.
OSIntExit();
#endif
}
#endif
}
|
|