21ic问答首页 - GD32F303串口不能产生空闲中断
GD32F303串口不能产生空闲中断
lesheng0022021-06-24
初次使用GD32F303芯片,以为没什么难度呢结果一上来就碰到问题了,串口不能产生空闲中断
看看我的代码是否有错
void NVIC_swtConfiguration(void)
{
/* USART interrupt configuration */
nvic_irq_enable(MY_USART_IRQ, 1, 0);
usart_interrupt_enable(MY_USART, USART_INT_IDLE);
/* enable USART TBE interrupt */
usart_interrupt_enable(MY_USART, USART_INT_RBNE);
}
// 配置通信端口
void funcSerialConfig(void)
{
// /* Enable GPIO clock
rcu_periph_clock_enable(MYRCC_USART_PORT);
rcu_periph_clock_enable(MYRCC_USART);
/* connect port to USARTx_Tx */
gpio_init(MY_USART_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, MY_USART_TX_PIN);
/* connect port to USARTx_Rx */
gpio_init(MY_USART_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, MY_USART_RX_PIN);
usart_deinit(MY_USART);
usart_baudrate_set(MY_USART, 115200);
usart_receive_config(MY_USART, USART_RECEIVE_ENABLE);
usart_transmit_config(MY_USART, USART_TRANSMIT_ENABLE);
NVIC_swtConfiguration();
usart_enable(MY_USART);
waitForSend = 1;
swt_RxCounter = 1;
usart_direct_send_data((const uint8_t*)"GD32F303VCT6 IDLE INT", 21);
}
中断函数
void UART3_IRQHandler(void)
{
uint16_t RxChar;
if((RESET != usart_interrupt_flag_get(MY_USART, USART_INT_FLAG_RBNE)) &&
(RESET != usart_flag_get(MY_USART, USART_FLAG_RBNE))){
RxChar = (usart_data_receive(MY_USART) & 0xfF);
/* receive data */
#if (ENABEL_DMA_TRANS == 0)
swt_recArray[swtRecieved][swt_RxCounter++] = RxChar;
if(swt_RxCounter >= EP_PACKET_MAX_SIZE)
{
usart_dma_irq_reciev_cb();
}
#endif
usart_flag_clear(MY_USART, USART_FLAG_RBNE);
}
if((RESET != usart_flag_get(MY_USART, USART_FLAG_IDLE)) &&
(RESET != usart_interrupt_flag_get(MY_USART, USART_INT_IDLE)))
{
RxChar = (usart_data_receive(MY_USART) & 0xfF);
usart_dma_irq_reciev_cb();
}
if((RESET != usart_flag_get(MY_USART, USART_FLAG_TBE)) &&
(RESET != usart_interrupt_flag_get(MY_USART, USART_INT_TBE)))
{
// usart_interrupt_flag_clear(MY_USART, USART_INT_TBE);
/* transmit data */
usart_data_transmit(MY_USART, swt_waitForsendArr[swt_currTxPointer][txPointer++]);
if(txCounter == txPointer){
usart_interrupt_disable(MY_USART, USART_INT_TBE);
}
usart_flag_clear(MY_USART, USART_FLAG_TBE);
}
if((RESET != usart_flag_get(MY_USART, USART_FLAG_TC)) &&
(RESET != usart_interrupt_flag_get(MY_USART, USART_INT_TC)))
{
usart_interrupt_flag_clear(MY_USART, USART_INT_TC);
usart_dma_send_finish_cb();
usart_flag_clear(MY_USART, USART_FLAG_TC);
}
}
当接收一批数据后,中断函数中红色这部分空闲中断代码不会执行,没找到什么原因。
有哪位大咖能指点一二。非常感谢
看看我的代码是否有错
void NVIC_swtConfiguration(void)
{
/* USART interrupt configuration */
nvic_irq_enable(MY_USART_IRQ, 1, 0);
usart_interrupt_enable(MY_USART, USART_INT_IDLE);
/* enable USART TBE interrupt */
usart_interrupt_enable(MY_USART, USART_INT_RBNE);
}
// 配置通信端口
void funcSerialConfig(void)
{
// /* Enable GPIO clock
rcu_periph_clock_enable(MYRCC_USART_PORT);
rcu_periph_clock_enable(MYRCC_USART);
/* connect port to USARTx_Tx */
gpio_init(MY_USART_PORT, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, MY_USART_TX_PIN);
/* connect port to USARTx_Rx */
gpio_init(MY_USART_PORT, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, MY_USART_RX_PIN);
usart_deinit(MY_USART);
usart_baudrate_set(MY_USART, 115200);
usart_receive_config(MY_USART, USART_RECEIVE_ENABLE);
usart_transmit_config(MY_USART, USART_TRANSMIT_ENABLE);
NVIC_swtConfiguration();
usart_enable(MY_USART);
waitForSend = 1;
swt_RxCounter = 1;
usart_direct_send_data((const uint8_t*)"GD32F303VCT6 IDLE INT", 21);
}
中断函数
void UART3_IRQHandler(void)
{
uint16_t RxChar;
if((RESET != usart_interrupt_flag_get(MY_USART, USART_INT_FLAG_RBNE)) &&
(RESET != usart_flag_get(MY_USART, USART_FLAG_RBNE))){
RxChar = (usart_data_receive(MY_USART) & 0xfF);
/* receive data */
#if (ENABEL_DMA_TRANS == 0)
swt_recArray[swtRecieved][swt_RxCounter++] = RxChar;
if(swt_RxCounter >= EP_PACKET_MAX_SIZE)
{
usart_dma_irq_reciev_cb();
}
#endif
usart_flag_clear(MY_USART, USART_FLAG_RBNE);
}
if((RESET != usart_flag_get(MY_USART, USART_FLAG_IDLE)) &&
(RESET != usart_interrupt_flag_get(MY_USART, USART_INT_IDLE)))
{
RxChar = (usart_data_receive(MY_USART) & 0xfF);
usart_dma_irq_reciev_cb();
}
if((RESET != usart_flag_get(MY_USART, USART_FLAG_TBE)) &&
(RESET != usart_interrupt_flag_get(MY_USART, USART_INT_TBE)))
{
// usart_interrupt_flag_clear(MY_USART, USART_INT_TBE);
/* transmit data */
usart_data_transmit(MY_USART, swt_waitForsendArr[swt_currTxPointer][txPointer++]);
if(txCounter == txPointer){
usart_interrupt_disable(MY_USART, USART_INT_TBE);
}
usart_flag_clear(MY_USART, USART_FLAG_TBE);
}
if((RESET != usart_flag_get(MY_USART, USART_FLAG_TC)) &&
(RESET != usart_interrupt_flag_get(MY_USART, USART_INT_TC)))
{
usart_interrupt_flag_clear(MY_USART, USART_INT_TC);
usart_dma_send_finish_cb();
usart_flag_clear(MY_USART, USART_FLAG_TC);
}
}
当接收一批数据后,中断函数中红色这部分空闲中断代码不会执行,没找到什么原因。
有哪位大咖能指点一二。非常感谢
赞0
评论
2021-12-09
赞0
那你的意思是,我要先判断空闲中断?然后再看其他中断
评论
2021-06-29
赞0
评论
2021-06-24
您需要登录后才可以回复 登录 | 注册