Linang
#include "debug.h"
void UART8_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USARTx_CFG(void)
{
GPIO_InitTypeDef GPIO_InitStructure = {0};
USART_InitTypeDef USART_InitStructure = {0};
NVIC_InitTypeDef NVIC_InitStructure = {0};
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART8 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_USART8,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOE, &GPIO_InitStructure);
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_Tx | USART_Mode_Rx;
USART_Init(UART8, &USART_InitStructure);
USART_ITConfig(UART8, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = UART8_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(UART8, ENABLE);
}
int main(void)
{
uint16_t a=2;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
SystemCoreClockUpdate();
Delay_Init();
USART_Printf_Init(115200);
USARTx_CFG();
printf("SystemClk:%d\r\n", SystemCoreClock);
printf("USART Interrupt TEST\r\n");
USART_SendData(UART8,a);
Delay_Ms(100);
while(1)
{
}
}
uint16_t b=0;
void UART8_IRQHandler(void)
{
if(USART_GetITStatus(UART8, USART_IT_RXNE) != RESET)
{
b=USART_ReceiveData(UART8);
printf("%d\r\n",b);
}
}