我在做串口的传输测试,想做一个电脑的串口工具输出什么字符,能让MCU转发出来到串口工具显示.可电脑发出去的字符,MCU接收不到,不知道是否串口中断没有生效:
如下:
hk32f030m_it.c文件中定义中断函数:
void USART1_IRQHandler(void)
{
uint8_t ucTemp;
if(USART_GetITStatus(DEBUG_USARTx,USART_IT_RXNE)!=RESET)
{
ucTemp = USART_ReceiveData(DEBUG_USARTx);
Usart_SendByte(DEBUG_USARTx,ucTemp);
}
}
--------------------------------------------------------------------------------------------------
在bsp_usart.c定义中断源等,并设置USART端口:
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
----------------------------------------------
void USART_Config(void)
{
中间省略:......................
USART_Init(DEBUG_USARTx, &USART_InitStructure);
USART_ITConfig(DEBUG_USARTx, USART_IT_RXNE, ENABLE);
USART_Cmd(DEBUG_USARTx, ENABLE);
NVIC_Configuration();
}
大家帮忙看看对吗?
|