2017-09-10 11:25 PM
HI.
I'm trying to test with simple UART as the below code,
I connect with RS232's TXD to GPIO_Pin_10 and
RS232's RXD to
GPIO_Pin_9.
There is no problem RS232 kit, but I can't receive data correctly from kit.
I always receive data '00'. I don't know what am I supposed to resolve this problem.
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;int main(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );//UART
//TXGPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);//RXGPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;GPIO_Init(GPIOA, &GPIO_InitStructure);// UART Port
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;USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);///////////while (1) { USART_SendData(USART1,'c'); }}I can receive the '00' data , when I push the reset button in stm32F429 kit.
Would you please let me know what am I missing ?
Solved! Go to Solution.
2017-09-11 03:47 AM
You should wait on TXE before sending the character
2017-09-11 03:47 AM
You should wait on TXE before sending the character
2017-09-11 06:24 AM
Thanks Clive,
I used this.
int putcharx(int ch)
{ while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); USART_SendData(USART1, (uint8_t)ch); return ch; }