第一次整F070的片子,只用USART3中断接收数据,但是调试发现中断一直没有进,哪位大侠看看什么问题:
static void USART3_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the USART3 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief USART3 GPIO 配置,工作模式配置。9600 8-N-1
* @param 无
* @retval 无
*/
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART3 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
/*开启GPIOB的外设时钟*/
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
/*配置映射外设管脚*/
GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_1);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_1);
/* USART1 GPIO config */
/* Configure USART3 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = USART3_TX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART3 Rx (PB.11) as input mode */
GPIO_InitStructure.GPIO_Pin = USART3_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* USART3 mode config */
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(USART3, &USART_InitStructure);
/* 使能串口3接收中断 */
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);
USART_ClearFlag(USART3, USART_FLAG_TC);
USART3_NVIC_Config();
}
void USART3_4_IRQHandler(void)
{
uint8_t UsartRes;
//接收中断(接收到的数据必须是0x0d 0x0a结尾)
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
UsartRes =USART_ReceiveData(USART3);//读取接收到的数据
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
IO配置有错,给你参考
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(Open407V_USART_TX_GPIO_CLK,ENABLE);
RCC_AHB1PeriphClockCmd(Open407V_USART_RX_GPIO_CLK,ENABLE);
RCC_APB2PeriphClockCmd(Open407V_USART_CLK,ENABLE);
GPIO_PinAFConfig(Open407V_USART_TX_GPIO_PORT, Open407V_USART_TX_SOURCE, Open407V_USART_TX_AF);
GPIO_PinAFConfig(Open407V_USART_RX_GPIO_PORT, Open407V_USART_RX_SOURCE, Open407V_USART_RX_AF);
/*
* Open407V_USART_TX -> PA9 , Open407V_USART_RX -PA10
*/
GPIO_InitStructure.GPIO_Pin = Open407V_USART_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = Open407V_USART_RX_PIN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*
USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit
*/
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_Rx | USART_Mode_Tx;
USART_Init(Open407V_USART, &USART_InitStructure);
/* Enable the Open407V_USART Transmit interrupt: this interrupt is generated when the
Open407V_USART transmit data register is empty */
USART_ITConfig(Open407V_USART,USART_IT_RXNE,ENABLE);
USART_Cmd(Open407V_USART, ENABLE);
// USART_NVIC_Config();
}
void USART_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the USARTx Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
一周热门 更多>