如题,usart2是可以进入中断的,但是usart3却无论如何也进不了,实在是找不出问题了,请教各位大神了、
代码如下:
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** º¯ÊýÃû³Æ: Usart_Init1
** ¹¦ÄÜÃèÊö: ´®¿ÚÒý½Å³õʼ»¯
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void Init_Usart1(unsigned long BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure; //¶¨ÒåÒ»¸öGPIO½á¹¹Ìå±äÁ¿
USART_InitTypeDef USART_InitStructure; //¶¨ÒåÒ»¸ö´®¿Ú½á¹¹Ìå
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);//ʹÄܸ÷¸ö¶Ë¿ÚʱÖÓ£¬ÖØÒª£¡£¡£¡
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //ÅäÖô®¿Ú½ÓÊն˿ڹҽӵ½9¶Ë¿Ú
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´Óù¦ÄÜÊä³öÍÆÍì
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ÅäÖö˿ÚËÙ¶ÈΪ50M
GPIO_Init(GPIOA, &GPIO_InitStructure); //¸ù¾Ý²ÎÊý³õʼ»¯GPIOA¼Ä´æÆ÷
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈë(¸´Î»×´Ì¬);
GPIO_Init(GPIOA, &GPIO_InitStructure); //¸ù¾Ý²ÎÊý³õʼ»¯GPIOA¼Ä´æÆ÷
USART_InitStructure.USART_BaudRate =BaudRate ; //²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //´«Êä¹ý³ÌÖÐʹÓÃ8λÊý¾Ý
USART_InitStructure.USART_StopBits = USART_StopBits_1; //ÔÚÖ¡½áβ´«Êä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); //ʹÄÜ´®¿ÚÖжϽÓÊÕ
__nop(); __nop();
USART_Cmd(USART1, ENABLE); //ʹÄÜ´®¿ÚÍâÉè
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** º¯ÊýÃû³Æ: Usart_Init2
** ¹¦ÄÜÃèÊö: ´®¿ÚÒý½Å³õʼ»¯
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void Init_Usart2(unsigned long BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure; //¶¨ÒåÒ»¸öGPIO½á¹¹Ìå±äÁ¿
USART_InitTypeDef USART_InitStructure; //¶¨ÒåÒ»¸ö´®¿Ú½á¹¹Ìå
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//ʹÄܸ÷¸ö¶Ë¿ÚʱÖÓ£¬ÖØÒª£¡£¡£¡
// GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE); //È«²¿remap usart3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //ÅäÖô®¿Ú½ÓÊն˿ڹҽӵ½2¶Ë¿Ú
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´Óù¦ÄÜÊä³öÍÆÍì
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ÅäÖö˿ÚËÙ¶ÈΪ50M
GPIO_Init(GPIOA, &GPIO_InitStructure); //¸ù¾Ý²ÎÊý³õʼ»¯GPIOA¼Ä´æÆ÷
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈë(¸´Î»×´Ì¬);
GPIO_Init(GPIOA, &GPIO_InitStructure); //¸ù¾Ý²ÎÊý³õʼ»¯GPIOA¼Ä´æÆ÷
USART_InitStructure.USART_BaudRate =BaudRate ; //²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //´«Êä¹ý³ÌÖÐʹÓÃ8λÊý¾Ý
USART_InitStructure.USART_StopBits = USART_StopBits_1; //ÔÚÖ¡½áβ´«Êä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(USART2, &USART_InitStructure); //¸ù¾Ý²ÎÊý³õʼ»¯´®¿Ú¼Ä´æÆ÷
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); //ʹÄÜ´®¿ÚÖжϽÓÊÕ
__nop(); __nop();
USART_Cmd(USART2, ENABLE); //ʹÄÜ´®¿ÚÍâÉ
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** º¯ÊýÃû³Æ: Usart_Init3
** ¹¦ÄÜÃèÊö: ´®¿ÚÒý½Å³õʼ»¯
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void Init_Usart3(unsigned long BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure; //¶¨ÒåÒ»¸öGPIO½á¹¹Ìå±äÁ¿
USART_InitTypeDef USART_InitStructure; //¶¨ÒåÒ»¸ö´®¿Ú½á¹¹Ìå
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//ʹÄܸ÷¸ö¶Ë¿ÚʱÖÓ£¬ÖØÒª£¡£¡£¡
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //ÅäÖô®¿Ú½ÓÊն˿ڹҽӵ½10¶Ë¿Ú
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´Óù¦ÄÜÊä³öÍÆÍì
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ÅäÖö˿ÚËÙ¶ÈΪ50M
GPIO_Init(GPIOB, &GPIO_InitStructure); //¸ù¾Ý²ÎÊý³õʼ»¯GPIOB¼Ä´æÆ÷
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿ÕÊäÈë(¸´Î»×´Ì¬);
GPIO_Init(GPIOB, &GPIO_InitStructure); //¸ù¾Ý²ÎÊý³õʼ»¯GPIOB¼Ä´æÆ÷
USART_InitStructure.USART_BaudRate = BaudRate ; //²¨ÌØÂÊ
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //´«Êä¹ý³ÌÖÐʹÓÃ8λÊý¾Ý
USART_InitStructure.USART_StopBits = USART_StopBits_1; //ÔÚÖ¡½áβ´«Êä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); //¸ù¾Ý²ÎÊý³õʼ»¯´®¿Ú¼Ä´æÆ÷
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE); //ʹÄÜ´®¿ÚÖжϽÓÊÕ
__nop(); __nop();
USART_Cmd(USART3, ENABLE); //ʹÄÜ´®¿ÚÍâÉè
}
/*
*********************************************************************************************************
* º¯ Êý Ãû: ConfigUartNVIC
* ¹¦ÄÜ˵Ã÷: ÅäÖô®¿ÚÓ²¼þÖжÏ.
*********************************************************************************************************
*/
static void ConfigUartNVIC(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); //--- ÔÚ bsp.c ÖÐ bsp_Init() ÖÐÅäÖÃÖжÏÓÅÏȼ¶×é */
/* ʹÄÜ´®¿Ú1ÖÐ¶Ï */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* ʹÄÜ´®¿Ú2ÖÐ¶Ï */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* ʹÄÜ´®¿Ú3ÖжÏt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** º¯ÊýÃû³Æ: USART2_IRQHandler
** ¹¦ÄÜÃèÊö: ´®¿ÚÖжϺ¯Êý
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void USART2_IRQHandler() //PC
{
unsigned char i;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
/*¶ÁÈ¡Ò»×Ö½ÚÊý¾Ý*/
i = USART_ReceiveData(USART2);
/* Çå³ýÖжϱê־λ */
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
}
COM2Receive[RxCount2++]=i;
}
}
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
** º¯ÊýÃû³Æ: USART3_IRQHandler
** ¹¦ÄÜÃèÊö: ´®¿ÚÖжϺ¯Êý
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
void USART3_IRQHandler() //board
{
unsigned char i;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
i = USART_ReceiveData(USART3);
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
}
//COM3Receive[RxCount3++]=i;
USART2_Send_Byte(i);
}
void bsp_InitUart(void)
{
ConfigUartNVIC();
Init_Usart1(115200);
Init_Usart2(115200);
Init_Usart3(19200);
} |