21ic问答首页 - GD32E230串口发送完成中断标识位没法清除!!
GD32E230串口发送完成中断标识位没法清除!!
sailor0072021-04-07
串口发送初始化为(PA9)中断发送方式,初始化代码如下:/* enable COM GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);
/* connect port to USARTx_Tx */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
/* connect port to USARTx_Rx */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);
/* USART configure */
usart_deinit(USART0);
usart_baudrate_set(USART0, baud);
usart_word_length_set(USART0, USART_WL_8BIT);
usart_stop_bit_set(USART0, USART_STB_1BIT);
usart_parity_config(USART0, USART_PM_NONE);
usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
nvic_irq_enable(USART0_IRQn, 0);
usart_interrupt_enable(USART0, USART_INT_TC);
usart_enable(USART0);
中断服务程序:
void USART0_IRQHandler(void)
{
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_TC))
{
usart_interrupt_flag_clear(USART0,USART_INT_FLAG_TC);
UplinkDrv_Sending((uint_8*)&(USART_TDATA(USART0)));
}
}
void UplinkDrv_Sending(uint_8 *reg)
{
if(UplinkFrame.Send.Pc >= UplinkFrame.Send.Len)
{
UplinkDrv_Recv_Creat();
}
else
{
*reg = UplinkFrame.Send.Buff[UplinkFrame.Send.Pc];
UplinkFrame.Send.Pc++;
}
}
目前是不到发送完一个字节就多次进入该发送中断完成服务程序,导致发送失败。
大拿有遇到相关问题吗?
rcu_periph_clock_enable(RCU_GPIOA);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART0);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);
/* connect port to USARTx_Tx */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
/* connect port to USARTx_Rx */
gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);
/* USART configure */
usart_deinit(USART0);
usart_baudrate_set(USART0, baud);
usart_word_length_set(USART0, USART_WL_8BIT);
usart_stop_bit_set(USART0, USART_STB_1BIT);
usart_parity_config(USART0, USART_PM_NONE);
usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
nvic_irq_enable(USART0_IRQn, 0);
usart_interrupt_enable(USART0, USART_INT_TC);
usart_enable(USART0);
中断服务程序:
void USART0_IRQHandler(void)
{
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_TC))
{
usart_interrupt_flag_clear(USART0,USART_INT_FLAG_TC);
UplinkDrv_Sending((uint_8*)&(USART_TDATA(USART0)));
}
}
void UplinkDrv_Sending(uint_8 *reg)
{
if(UplinkFrame.Send.Pc >= UplinkFrame.Send.Len)
{
UplinkDrv_Recv_Creat();
}
else
{
*reg = UplinkFrame.Send.Buff[UplinkFrame.Send.Pc];
UplinkFrame.Send.Pc++;
}
}
目前是不到发送完一个字节就多次进入该发送中断完成服务程序,导致发送失败。
大拿有遇到相关问题吗?
赞0
评论
2021-04-13
赞0
评论
2021-04-13
您需要登录后才可以回复 登录 | 注册