2021-04-22 11:07 AM
int USART2_Write(int ch){
//wait for TX buffer empty
while (!(USART2->SR & USART_SR_TXE)) {}
USART2->DR = ch;
return 0;
}
int USART2_Read(void) {
while (!(USART2->SR & USART_SR_RXNE)) {}
return USART2->DR;
}
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define GETCHAR_PROTOTYPE int __io_getchar (void)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#define GETCHAR_PROTOTYPE int fgetc(FILE * f)
#endif
PUTCHAR_PROTOTYPE{
USART2_Write(ch);
return ch;
}
GETCHAR_PROTOTYPE {
uint8_t ch = 0;
ch = USART2_Read();
}
2021-04-22 11:51 AM
hello
GETCHAR_PROTOTYPE must return the ch value.
2021-04-22 12:03 PM
I just added that but still no success
2021-04-22 03:30 PM
Did USART2_Read(void) ever called? And if called, did ever received something ?
The provided information does not give enough clues help.