-
使能串口发送中断, 出现前导乱码, 问题求解
使用芯片华大 HC32F460PETB, 每次使能 Uart 发送中断, 串口就会发送 "11 11 11 00" (HEX) 3-4 BYTE 的乱码, 这个时候还未进行中断处理, 前导乱码已经发出!向给位请教一下, 怎么处理, 消除前导乱码 /****************************************************************************** brief: 发送中断 param: None retval: None *****************************************************************************/ static void UsartTxIrqCallback(void) { uint8_t u8Data = 0u; if (Ok == RingBufRead(&m_stcRingBuf_Out, &u8Data)) { USART_SendData(USART_CH, (uint16_t)u8Data); } // 如果数据已经发送完毕,关闭发送中断,打开发送完毕中断 if (IS_RING_BUFFER_EMPTY(&m_stcRingBuf_Out)) { // 发送数据完毕,关发送中断 USART_FuncCmd(USART_CH, UsartTxEmptyInt, Disable); // 打开发送完毕中断 USART_FuncCmd(USART_CH, UsartTxCmpltInt, Enable); } } /****************************************************************************** brief: 发送完毕中断 param: None retval: None *****************************************************************************/ static void UsartTxCmpltIrqCallback(void) { // 关闭发送中断,关闭完毕中断 USART_FuncCmd(USART_CH, UsartTx, Disable); USART_FuncCmd(USART_CH, UsartTxCmpltInt, Disable); // 发送闲 0 m_u8Status = 0u;; } /****************************************************************************** brief: 启动发送中断 param: void retval: void 注: 如果忙或者为空, 就没有必要启动发送 *****************************************************************************/ void UartA_Start_Send(void) { register rt_base_t level; uint8_t u8Data = 0u; // 必须原子, 因为要支持边发边加 level = rt_hw_interrupt_disable(); if ((!IS_RING_BUFFER_EMPTY(&m_stcRingBuf_Out)) && (0u == m_u8Status)) { // 装入首字符 /*if (Ok == RingBufRead(&m_stcRingBuf_Out, &u8Data)) { USART_SendData(USART_CH, (uint16_t)u8Data); USART_FuncCmd(USART_CH, UsartTxAndTxEmptyInt, Enable); //设置状态=发送中 m_u8Status = 1u; }*/ USART_FuncCmd(USART_CH, UsartTxAndTxEmptyInt, Enable); //设置状态=发送中 m_u8Status = 1u; } rt_hw_interrupt_enable(level); }
1451浏览量 3回复量 关注量 -
GD32F103RB映射UART0到PB6,PB7失败怎么解决?
[color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px] 我在作用GD32F103RB时,LQFP64将串口0重映射到PB6,PB7时串口发送数据时无输出。用示波器测量IO口无波形。但是串口中断可以进去。[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px] PB6 - Remap: USART_RX[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px] PB7 - Remap: USART_TX[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]//初始化程序如下:[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]nvic_irq_enable(USART0_IRQn, 14, 0); //[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]// remap uart0[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]rcu_periph_clock_enable(RCU_AF); [/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]/* enable GPIO clock */[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]rcu_periph_clock_enable( RCU_GPIOB); // clock already seted[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]rcu_periph_clock_enable( RCU_GPIOB);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]/* connect port to USARTx_Tx */[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]gpio_init(GPIOB, GPIO_MODE_OUT_OD, GPIO_OSPEED_2MHZ, GPIO_PIN_6);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]/* connect port to USARTx_Rx */[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]gpio_init(GPIOB, GPIO_MODE_OUT_OD, GPIO_OSPEED_2MHZ, GPIO_PIN_7);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]/* enable USART clock */[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]rcu_periph_clock_enable(RCU_USART0);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]/* USART configure */[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_deinit(USART0);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_baudrate_set(USART0, 9600);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_word_length_set(USART0, USART_WL_8BIT);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_stop_bit_set(USART0, USART_STB_1BIT);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_parity_config(USART0, USART_PM_NONE);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_receive_config(USART0, USART_RECEIVE_ENABLE);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]usart_enable(USART0);[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]// interrupt enable[/size][/font][/backcolor][/color] [color=#444444][backcolor=rgb(242, 249, 253)][font=Tahoma, "][size=16px]//usart_interrupt_enable(USART0, USART_INT_TBE);[/size][/font][/backcolor][/color]
4616浏览量 2回复量 关注量 -
求助-GD32F103RB将UART0重映射到PB6,PB7上无输出是怎么回事?
我在作用GD32F103RB时,LQFP64将串口0重映射到PB6,PB7时串口发送数据时无输出。用示波器测量IO口无波形。但是串口中断可以进去。 PB6 - Remap: USART_RX PB7 - Remap: USART_TX //初始化程序如下: nvic_irq_enable(USART0_IRQn, 14, 0); // // remap uart0 rcu_periph_clock_enable(RCU_AF); gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE); /* enable GPIO clock */ rcu_periph_clock_enable( RCU_GPIOB); // clock already seted rcu_periph_clock_enable( RCU_GPIOB); /* connect port to USARTx_Tx */ gpio_init(GPIOB, GPIO_MODE_OUT_OD, GPIO_OSPEED_2MHZ, GPIO_PIN_6); /* connect port to USARTx_Rx */ gpio_init(GPIOB, GPIO_MODE_OUT_OD, GPIO_OSPEED_2MHZ, GPIO_PIN_7); /* enable USART clock */ rcu_periph_clock_enable(RCU_USART0); /* USART configure */ usart_deinit(USART0); usart_baudrate_set(USART0, 9600); 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_receive_config(USART0, USART_RECEIVE_ENABLE); usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); usart_enable(USART0); // interrupt enable //usart_interrupt_enable(USART0, USART_INT_TBE);
8922浏览量 3回复量 关注量 -
GD32F407IGH6串口问题
8M外部晶振 PLL 168MUSART0实际波特率只有设置波特率的三分之一而且最后一个字节不对(全1)或丢失 请问有人有过类似问题吗
6185浏览量 4回复量 关注量 -
bootload中断异常 sos
[i=s] 本帖最后由 tyw 于 2021-8-7 16:34 编辑 [/i] 下面是跳转程序 [color=#000000][backcolor=white] [font=Consolas, "]void IAP_Load_APP(uint32_t appxaddr) { RCC->APB1RST = 0xFFFFFFFF; RCC->APB2RST = 0xFFFFFFFF; RCC->APB1RST = 0x00000000; RCC->APB2RST = 0x00000000; if (((*(uint32_t *)appxaddr) & 0x2FFF8000) == 0x20000000) //检查栈顶地址是否合法. { jump2app = (iapfun) * (vu32 *)(appxaddr + 4); //用户代码区第二个字为程序开始地址(复位地址) __set_MSP(*(vu32 *)appxaddr); //初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址) //MSR_MSP(*(vu32*)appxaddr); //SCB->VTOR = appxaddr; jump2app(); //跳转到APP. } } [/font] [font=Consolas, "]下面是APP串口中断测试函数void USART1_IRQHandler(void) { //AT32_LEDn_ON(LED2); intrupt_NUM++; if (USART_GetITStatus(USART1, USART_INT_RDNE) != RESET) { /* Read one byte from the receive data register */ //RxBuffer1[1] = USART_ReceiveData(USART1);//需要读取数据清除空闲标志位,否则会循环中断 USART_ClearFlag(USART1, USART_FLAG_RDNE); // AT32_LEDn_Toggle(LED2); RxBuffer1[USART_INT_RDNE_NUM] = USART_ReceiveData(USART1); USART_INT_RDNE_NUM++; if (USART_INT_RDNE_NUM > 98) USART_INT_RDNE_NUM = 98; } if (USART_GetITStatus(USART1, USART_INT_IDLEF) != RESET) { /* Read one byte from the receive data register */ // RxBuffer1[2] = USART1 -> STS; RxBuffer1[USART_INT_RDNE_NUM - 1] = USART_ReceiveData(USART1); //需要读取数据用于清除空闲标志位,否则会死机 USART_INT_RDNE_NUM = 0; USART_INT_IDLEF_NUM++; USART1_END = 0; } //printf(" %d %d %d", intrupt_NUM, USART_INT_RDNE_NUM, USART_INT_IDLEF_NUM); if (USART_GetITStatus(USART1, USART_INT_TRAC) != RESET) { USART_INT_TRAC_NUM++; } } int main(void) { AT32_Board_Init(); MX_USART1_UART_Init(); printf("Tset OTA APP !!!! \n\r"); extern uint8_t USART1_END, intrupt_NUM, USART_INT_RDNE_NUM, USART_INT_IDLEF_NUM, USART_INT_TRAC_NUM; extern uint8_t RxBuffer1[100]; while (1) { if (USART1_END == 0) { printf("RxBuffer1:%s", RxBuffer1); USART1_END = 1; if (strstr((char *)RxBuffer1, "LED_ON")) { AT32_LEDn_ON(LED2); } if (strstr((char *)RxBuffer1, "LED_OFF")) { AT32_LEDn_OFF(LED2); } memset(RxBuffer1, 0, sizeof(RxBuffer1)); } AT32_LEDn_Toggle(LED3); Delay_ms(100); } } 说明一下 APP函数单独下载到MCU中是可以运行的通过OTA后就出现不正常的情况OTA后的日志[16:19:17.371]收←◆Go to updata ^_^Tset OTA APP !!!! [16:19:19.462]发→◇LED_ON□[16:19:19.474]收←◆RxBuffer1:[16:19:20.727]发→◇LED_ON□[16:19:20.775]收←◆RxBuffer1:[16:19:21.721]发→◇LED_ON□[16:19:21.776]收←◆RxBuffer1:[16:19:22.375]发→◇LED_ON□[16:19:22.378]收←◆RxBuffer1:[16:19:22.846]发→◇LED_ON□[16:19:22.878]收←◆RxBuffer1:[16:19:23.279]发→◇LED_ON□[16:19:23.379]收←◆RxBuffer1:[16:19:23.854]发→◇LED_ON□[16:19:23.880]收←◆RxBuffer1:不能正常的打印出接收到的数据 [/font] [/backcolor][/color]
3576浏览量 0回复量 关注量 -
关于GD32F103 uart sos
[font=Tahoma][font=Tahoma][size=10.5pt]我用[/size][/font][/font][font=Tahoma][size=10.5pt]GD32F103 做串口通讯,USART0、USART1、USART2都能正常工作,用同样的初始化程序,UART3、UART4 无法通讯。[/size][/font][align=left]用示波器监视数据线,发现电压值不正确,有知道问题出在哪里的吗?[/align]
3035浏览量 0回复量 关注量 -
GD32F303串口不能产生空闲中断
初次使用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); } [color=#f000f0] if((RESET != usart_flag_get(MY_USART, USART_FLAG_IDLE)) && [/color] [color=#f000f0] (RESET != usart_interrupt_flag_get(MY_USART, USART_INT_IDLE)))[/color] [color=#f000f0] {[/color] [color=#f000f0] RxChar = (usart_data_receive(MY_USART) & 0xfF);[/color] [color=#f000f0] usart_dma_irq_reciev_cb();[/color] [color=#f000f0] }[/color] 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); } } 当接收一批数据后,中断函数中红色这部分空闲中断代码不会执行,没找到什么原因。 有哪位大咖能指点一二。非常感谢
4758浏览量 3回复量 关注量 -
GD32F103串口问题 sos
串口初始化时,校验位为偶校验,数据位8时,单片机发出来的数据是乱码,后来问了一下芯片厂家,他们说设置校验位的时候数据位要设置成9,但是发出来的数据还是部分是乱码。重点来了:我设置无校验,数据位8时,跟上位机通信,无论串口组手有没有校验位(奇偶或者无校验)都能通信成功,且数据正常,这谁能给解释一下原因。串口相关代码如下: void CIOControl::USART_Config(void) { rcu_periph_clock_enable(RCU_USART2); gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10); gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_11); /* USART configure */ usart_deinit(USART2); usart_baudrate_set(USART2, 2400); usart_word_length_set(USART2, USART_WL_8BIT); usart_stop_bit_set(USART2, USART_STB_1BIT); usart_parity_config(USART2, USART_PM_NONE); usart_hardware_flow_rts_config(USART2, USART_RTS_DISABLE); usart_hardware_flow_cts_config(USART2, USART_CTS_DISABLE); usart_receive_config(USART2, USART_RECEIVE_ENABLE); usart_transmit_config(USART2, USART_TRANSMIT_ENABLE); usart_enable(USART2); usart_interrupt_enable(USART2, USART_INT_RBNE); nvic_irq_enable(USART2_IRQn, 1, 0); } INT8U CUART::SendData(INT8U *DataBuf, INT16U DataLen) { INT8U j; for(INT16U i = 0; i < DataLen; i++) { usart_data_transmit(m_UARTNum, DataBuf[i]); Delay_ms(1); for(j = 0; j < 200; j++) { if(usart_flag_get(m_UARTNum, USART_FLAG_TC) != RESET) { usart_flag_clear(m_UARTNum, USART_FLAG_TC); break; } Delay_us(100); } if(j == 200) //20ms没有发送成功,则认为发送失败 { return FALSE; } } return TRUE; }
2109浏览量 0回复量 关注量 -
GD32E103VB Uart0 sos
为什么我用的GD32E103VB 的Uart打印出来是乱码。。。代码如下:#include "gd32e10x.h" #include "gd32e103v_eval.h" #include "systick.h" #include
/* retarget the C library printf function to the USART */ int fputc(int ch, FILE *f) { usart_data_transmit(USART0, (uint8_t)ch); while(RESET == usart_flag_get(USART0, USART_FLAG_TBE)); return ch; } void uart_init(void) { rcu_periph_clock_enable(RCU_AF); /* enable GPIO clock */ rcu_periph_clock_enable(RCU_GPIOA); //gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE); /* enable USART clock */ rcu_periph_clock_enable(RCU_USART0); /* connect port to USARTx_Tx */ gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9); /* connect port to USARTx_Rx */ gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10); //gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE); /* USART configure */ usart_deinit(USART0); usart_baudrate_set(USART0, 115200U); usart_receive_config(USART0, USART_RECEIVE_ENABLE); usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); usart_enable(USART0); } int main(void) { systick_config(); uart_init(); while(1) { printf("hello world\n"); } } 打印结果如下: l"l"Xl"H$ ll"l"XlDl"l。。。。。。 2245浏览量 0回复量 关注量 -
STM32串口通信控制电机
我想用串口通信来控制无刷电机,串口代码借用正点原子,目前串口可以接收到发送的指令,但是不能控制电机,希望有前辈帮我解答一下,附上主函数代码int main(void) { u8 t; //typedef unsigned char uint8_t; u8 len; u16 times=0; //typedef unsigned short uint16_t; volatile unsigned char HALL_flag; LED_Init(); delay_init(); uart2_init(9600); //串口初始化为9600 PWM_GPIO_Init(); HALL_GPIO_Init(); LED1=1; while(1) { if(USART_RX_STA&0x8000) { len=USART_RX_STA&0x3fff; printf("\r\n您发送的消息为:\r\n"); for(t=0;t
DR=USART_RX_BUF[t]; while((USART2->SR&0X40)==0); } printf("\r\n\r\n");//插入换行 USART_RX_STA=0; if(strcmp((char*)USART_RX_BUF,"电机1正转")==0) { HALL_flag =1; BLDC_CW(); printf("\r\n行走电机正转\r\n"); } if(strcmp((char*)USART_RX_BUF,"电机1停止")==0) { HALL_flag =0; BLDC_STOP(); printf("\r\n行走电机停止\r\n"); } }else { times++; if(times%5000==0) { printf("\r\nALIENTEK MiniSTM32开发板 串口实验\r\n"); printf("正点原子@ALIENTEK\r\n\r\n\r\n"); } if(times%200==0)printf("请输入数据,以回车键结束\r\n"); if(times%30==0)LED1=!LED1;//闪烁LED,提示系统正在运行. delay_ms(10); } } } 4558浏览量 9回复量 关注量 -
RCU库中没有AF sos
USART可以发送但不能接收,网上有的说要rcu_periph_clock_enable(RCU_AF),但我的RCU中没有AF时钟怎么办。
1251浏览量 0回复量 关注量 -
GD32E230串口发送完成中断标识位没法清除!!
串口发送初始化为(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++; } } 目前是不到发送完一个字节就多次进入该发送中断完成服务程序,导致发送失败。 大拿有遇到相关问题吗?
1360浏览量 2回复量 关注量 -
GD32使用DMA发送问题 sos
[i=s] 本帖最后由 tyw 于 2021-3-8 14:02 编辑 [/i] [font=Consolas, "][color=#000000][backcolor=white]void u3_printf(char* fmt,...) { va_list ap; va_start(ap,fmt); vsprintf((char*)USART3_TX_BUF,fmt,ap); va_end(ap); dma_channel_disable(DMA0,DMA_CH1); dma_memory_address_config(DMA0,DMA_CH1,(uint32_t)USART3_TX_BUF); dma_transfer_number_config(DMA0,DMA_CH1,strlen((const char*)USART3_TX_BUF)); dma_channel_enable(DMA0,DMA_CH1); usart_dma_transmit_config(USART2, USART_DENT_ENABLE);//使能串口DMA发送 while(RESET == dma_flag_get(DMA0, DMA_CH1, DMA_FLAG_FTF)){}; /* wait DMA Channel transfer complete */ memset(USART3_TX_BUF,0,USART3_MAX_SEND_LEN); } [/backcolor][/color][/font] 如上代码:第一次发送正常,第二次发送,对端只能收到相应长度的空字符怀疑是第二次发送的时候没有从首地址开始发送,同样代码stm32是正常的
1626浏览量 0回复量 关注量