qq4988 发表于 2014-9-26 08:58 
是中断接收吗?最好把程序贴上来,大家一起找问题
对,usart1的中断接收。程序如下:
uint8_t WL433_rec_data[128];
void USART1_IRQHandler(void)
{
static uint16_t i = 0,maxlen=0;;
printf("uart1-interrupt..aa\n");
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);//clear interrupt flag
printf("i = %d\n",i);
WL433_rec_data[i++] = (uint8_t)USART_ReceiveData(USART1);
USART_SendData(USART1,WL433_rec_data[i-1]);
if(i>=128)
i = 0;
}
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//ÉèÖÃÓÅÏȼ¶·Ö×é2(3,3)£¬Ö»ÐèÉèÖÃÒ»´Î
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //ͨµÀÉèÖÃΪ´®¿Ú1ÖжÏ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //ÖжÏÕ¼Ïȵȼ¶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //ÖжÏÏìÓ¦ÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //´ò¿ªÖжÏ
NVIC_Init(&NVIC_InitStructure); //³õʼ»¯
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
//usart ͬ²½Ê±ÖÓclk³õʼ»¯£¬ÒòΪûÓÐÓõ½Í¬²½Í¨ÐÅģʽ£¬¹ÊCR2¼Ä´æÆ÷.11=USART_Clock_Disableµô¼´¿É¡£
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART1, &USART_ClockInitStructure);//uart4&5²»Ö§³Öͬ²½Ê±ÖÓ
USART_ClockInit(USART2, &USART_ClockInitStructure);//
USART_ClockInit(USART3, &USART_ClockInitStructure);//
//USART1 for WL433
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);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//½ÓÊռĴæÆ÷²»Îª¿ÕÖжÏʹÄÜ
}
|