Question
Retargeting stdio to USART1
Posted on August 02, 2011 at 04:56
Hello,
I have USART1 configured properly and running. I am using the following code to write to the USART1 [code] USART_SendData(USART1,'A'); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); [/code] The above code is working. The problem is coming when I am trying to retarget the output of printf() to USART1 Following is the code to overide the fputc() function [code] /** * @brief Retargets the C library printf function to the USART. * @param None * @retval None */ int fputc(int ch, FILE *f) { /* Place your implementation of fputc here */ /* e.g. write a character to the USART */ USART_SendData(USART1,(uint8_t)ch); /* Loop until the end of transmission */ while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET); return ch; } [/code] But when ever I am trying to use printf() the USART start sending NULL's repeatedly. Tool Chain: RV Compiler on Keil RVMDK (demo) Any help is appreciated!