关于printf函数重定向的问题
如题,在STM32上对printf进行重定向,printf输出最后多了0x10,0x02,显示为类似制表符的东西,很费解啊,求助!!!附部分代码和效果图如下:voidUS...
如题,在STM32上对printf进行重定向,printf输出最后多了0x10,0x02,显示为类似制表符的东西,很费解啊,求助!!!
附部分代码和效果图如下:
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USART1 configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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;
/* Configure the USART1*/
USART_Init(USART1, &USART_InitStructure);
USART_Init(USART2, &USART_InitStructure);
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_GPIO_Configuration();
}
int fputc(int ch, FILE *f)
{
/* Write a character to the USART */
USART_SendData(USART1, (u8) ch);
/* Loop until the end of transmission */
while(!(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == SET))
{
}
return ch;
}
main(void)
{
...
printf("CESHI");
...
}
输出多了 10 02 ,不知道是为什么。
另外scanf的重定义是只修改fgetc就可以了嘛?为什么我改了在编译的时候就报错? 展开
附部分代码和效果图如下:
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USART1 configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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;
/* Configure the USART1*/
USART_Init(USART1, &USART_InitStructure);
USART_Init(USART2, &USART_InitStructure);
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_GPIO_Configuration();
}
int fputc(int ch, FILE *f)
{
/* Write a character to the USART */
USART_SendData(USART1, (u8) ch);
/* Loop until the end of transmission */
while(!(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == SET))
{
}
return ch;
}
main(void)
{
...
printf("CESHI");
...
}
输出多了 10 02 ,不知道是为什么。
另外scanf的重定义是只修改fgetc就可以了嘛?为什么我改了在编译的时候就报错? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询