cancel
Showing results for 
Search instead for 
Did you mean: 

UART receiving data fail issue

Carter Lee
Associate III
Posted on September 11, 2017 at 08:25

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 

//TX

GPIO_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);

//RX

GPIO_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.

0690X000006044GQAQ.jpg

Would you please let me know what am I missing ?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on September 11, 2017 at 12:47

 

You should wait on TXE before sending the character

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2
Posted on September 11, 2017 at 12:47

 

You should wait on TXE before sending the character

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 11, 2017 at 13:24

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;

}