初中生
最后登录1970-1-1
在线时间 小时
注册时间2014-2-21
|
楼主 |
发表于 2014-2-23 17:27:40
|
显示全部楼层
随风 发表于 2014-2-21 21:04
把你配置的代码帖出来吧。肯定是配置没配置完全
void USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
// NVIC_Configuration();
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
USART_InitStructure.USART_BaudRate=9600;
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;
/* Configure the USART1 */
USART_Init(USART1, &USART_InitStructure);
/* INIT USART1 */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);
USART_InitStructure.USART_BaudRate=9600;
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;
/* Configure the USART2 */
USART_Init(USART2, &USART_InitStructure);
/* INIT USART2 */
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
/* Enable the USART2 */
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
USART_ClearFlag(USART2,USART_FLAG_TC);
USART_Cmd(USART2, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级分组形式1,即抢占级占一位,优先级占3位
/****************UART2全局中断使能***********************/
NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
int main(void)
{
vu16 i=500;
// gpio_initi();
NVIC_Configuration();
USART_Config();
/* start_gsm();
Delay(20000000);
USART_printf(USART2,"AT\r\n");
Delay(2000000);
USART_printf(USART2,"AT+CGPSPWR=1\r\n");
Delay(200000);
USART_printf(USART2,"AT+CGPSRST=1\r\n");
Delay(200000);
USART_printf(USART2,"AT+CGPSIPR=9600\r\n");*/
while(1)
{
i=500;
if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) != RESET)
{
USART_SendData(USART2,USART_ReceiveData(USART2));
while(i--);
}
}
}
|
|