printf输出卡顿
/********************************** (C) COPYRIGHT ******************************** File Name : Main.c
* Author : WCH
* Version : V1.0
* Date : 2020/08/06
* Description : 串口1收发演示
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "CH57x_common.h"
uint8_t TxBuff[] = "This is a tx exam\r\n";
uint8_t RxBuff;
uint8_t trigB;
/*********************************************************************
* @fn main
*
* @brief 主函数
*
* @returnnone
*/
int main()
{
uint8_t len;
SetSysClock(CLK_SOURCE_PLL_60MHz);
/* 配置串口1:先配置IO口模式,再配置串口 */
GPIOA_SetBits(GPIO_Pin_9);
GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU); // RXD-配置上拉输入
GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
UART1_DefInit();
#if 1 // 测试串口发送字符串
UART1_SendString(TxBuff, sizeof(TxBuff));
#endif
#if 1 // 查询方式:接收数据后发送出去
PRINT("start\n");
while(1)
{
// len = UART1_RecvString(RxBuff);
// if(len)
// {
// UART1_SendString(RxBuff, len);
// }
//UART1_SendString("1234", 4);
printf("666");
DelayMs(1000);
}
#endif
#if 0 // 中断方式:接收数据后发送出去
UART1_ByteTrigCfg(UART_7BYTE_TRIG);
trigB = 7;
UART1_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_LINE_STAT);
PFIC_EnableIRQ(UART1_IRQn);
#endif
while(1);
}
/*********************************************************************
* @fn UART1_IRQHandler
*
* @brief UART1中断函数
*
* @returnnone
*/
__attribute__((interrupt("WCH-Interrupt-fast")))
__attribute__((section(".highcode")))
void UART1_IRQHandler(void)
{
volatile uint8_t i;
switch(UART1_GetITFlag())
{
case UART_II_LINE_STAT: // 线路状态错误
{
UART1_GetLinSTA();
break;
}
case UART_II_RECV_RDY: // 数据达到设置触发点
for(i = 0; i != trigB; i++)
{
RxBuff = UART1_RecvByte();
UART1_SendByte(RxBuff);
}
break;
case UART_II_RECV_TOUT: // 接收超时,暂时一帧数据接收完成
i = UART1_RecvString(RxBuff);
UART1_SendString(RxBuff, i);
break;
case UART_II_THR_EMPTY: // 发送缓存区空,可继续发送
break;
case UART_II_MODEM_CHG: // 只支持串口0
break;
default:
break;
}
}
默认的打印库需要增加\n否则累计到500字节左右才会打印,如果不需要增加\n可以根据此链接修改打印库:https://www.cnblogs.com/risc5-ble/p/15951072.html 存不存存在有别的任务阻塞的这种情况?? 我建议你检查一下`printf`的使用,尤其是在循环中
页:
[1]