下面是我的程序设置,用查询方式工作,串口发送和接受都试过,可以正常工作,但是如果用中断方式,不会跳入中断,请教一下是哪里出问题了。
void USART_Gpio_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_UART8);
GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_UART8);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
void USART_Config(void)
{
USART_InitTypeDef Usart_InitStructure;
USART_Gpio_Config();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART8, 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;
USART_Init( UART8 , &Usart_InitStructure);
USART_Cmd(UART8,ENABLE);
}
void USARVT_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = UART8_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(UART8, USART_IT_RXNE, ENABLE);
USART_ITConfig(UART8, USART_IT_TXE, ENABLE);
}
void UART8_IRQHandler(void)
{
char receive;
char a=0x05;
a=a+1;
if(USART_GetITStatus(UART8, USART_IT_RXNE) != RESET)
{
receive = USART_ReceiveData( UART8 ) ;
USART_SendData(UART8,a);
}
if(USART_GetITStatus(UART8, USART_IT_TXE) != RESET)
{
USART_SendData(UART8,a);
}
}
|