我在main函数中调用延时函数
SysTick_Delay(400);
LED_ON(LED1);
SysTick_Delay(500);
LED_OFF(LED1);
只有调用延时函数的时候就会这样。
如果程序中开了串口,我使用的是USART3,程序总是在串口中断,出不了了,请问该如何解决。
void USART3_IRQHandler(void)
{
uint8_t RxBuf;
if(USART_GetITStatus(USART3,USART_IT_RXNE)!=RESET)
{
RxBuf = USART_ReceiveData(USART3);
RS485_RX_BUF[RS485_RX_GL] = RxBuf;
RS485_RX_GL++;
if((RS485_RX_BUF[0]!=RS485STARTCODE)||(RS485_RX_GL>=8))
{
RS485_RX_GL = 0;
RS485_RX_STA = 0;
}
if(RS485_RX_BUF[7]==RS485ENDCODE)
{
RS485_RX_GL=0;
RS485_RX_STA=1;
printf(" RS485 Receive Data ok!\n\r");
}
//-----------------------------------------------
USART_ClearITPendingBit(USART3,USART_IT_RXNE);
}
if(USART_GetFlagStatus(USART3,USART_FLAG_ORE) == SET)
{
USART_ClearFlag(USART3,USART_FLAG_ORE);
}
}
void RS485_TX_EN2(void)
{
GPIO_SetBits(RS485_EN2_PORT,RS485_EN2_PIN);
}
void RS485_Init(void)
{
/*-------------¶¨Òå½á¹¹Ìå±äÁ¿----------*/
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/*--------------ʹÄÜÏàÓ¦ÍâÉèµÄʱÖÓ------*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
GPIO_InitStructure.GPIO_Pin = RS485_EN2_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(RS485_EN2_PORT, &GPIO_InitStructure);
USART_DeInit(USART3);
/*-------------ÅäÖÃUSART3_TX(PB.10)----------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
/*-------------ÅäÖÃUSART3_RX(PB.11)----------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&GPIO_InitStructure);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3,DISABLE);
RS485_RX_EN2(); //ÉèÖÃΪ½ÓÊÕģʽ
/*------------USARTdµÄ¸÷¸ö²ÎÊýÅäÖÃ----------*/
USART_InitStructure.USART_BaudRate = 9600; //ÉèÖÃUSART´«ÊäµÄ²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8λÊý¾Ýλ
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(USART3,&USART_InitStructure); //³õʼ»¯USART3µÄ¼Ä´æÆ÷
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USART1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// USART_ClearITPendingBit(USART3, USART_IT_TC);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
USART_Cmd(USART3,ENABLE);
}
|