usart还是接受不了字符串,谁帮我看看程序哪里出问题啊
[复制链接]
简化以后的主程序如下
#include "stm32f10x_lib.h"
#include "USART.h" ErrorStatus HSEStartUpStatus; u8 Rxdata2[]; vu8 Rxnbr2; GPIO_InitTypeDef GPIO_InitStructure; void GPIO_Configuration(void) { /* Configure USART1 Tx (PA.09) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART1 Rx (PA.10) as input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(GPIOB, &GPIO_InitStructure);
} //系统中断管理 void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
#ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the EXTI15_10 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
//配置系统时钟,使能各外设时钟 void RCC_Configuration(void) { /* RCC system reset(for debug purpose) */ RCC_DeInit();
/* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS) { /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2);
/* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_4);
/* Enable PLL */ RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }
/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } /* Enable USART1 and GPIOA clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 |RCC_APB1Periph_USART2| RCC_APB2Periph_GPIOA, ENABLE); }
//配置所有外设 void Init_All_Periph(void) { RCC_Configuration(); GPIO_Configuration(); NVIC_Configuration(); USART1_Configuration();
USART1Write((u8*)"AT\r\n",sizeof("AT\r\n")) ;
}
void Delay(vu32 nCount) { for(; nCount != 0; nCount--); }
int main(void) { Init_All_Periph(); }
然后我直接将usart的接收和发送短接在一起
中断程序为
extern u8 Rxdata2[]; extern vu8 Rxnbr2; #define counter_max 0xff void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { Rxdata2[Rxnbr2++] = (USART_ReceiveData(USART1)); USART_ClearITPendingBit(USART1, USART_IT_RXNE); if(Rxnbr2 == counter_max|Rxdata2[Rxnbr2]=='\0') { /* Disable the USART2 Receive interrupt */
USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
} } }
但是调试时接收的数据只有Rxdata2[0],也就是只能就收到A,后面的没有。紧急求助啊
|