cancel
Showing results for 
Search instead for 
Did you mean: 

USART NOT receiving nothing

timothy
Associate II
Posted on August 07, 2013 at 07:12

Im using usart2 and i know its sending data but will not receive im using :

rx_data = USART_ReceiveData(USART2);

to save the data then using a

while(rx_data > 0 ) 

{ do stuff}

any suggestions about why its not receiving?

#poorly-framed-question #usart #usart-stm32f103
6 REPLIES 6
jpeacock2399
Associate II
Posted on August 07, 2013 at 15:46

Are you first checking the RXNE flag to see if data is available before trying to read it from the USART?

  Jack Peacock
timothy
Associate II
Posted on August 07, 2013 at 18:07

yes i use

while( USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == SET); // checking flag 
{rx_data = USART_ReceiveData(USART2);
}

then once rx_data >0 it does stuff, but i dont understand why it doesnt react. Im feeding the USART2.TX right into the USART2.RX. Am i doing something wrong?
Posted on August 07, 2013 at 18:56

Am i doing something wrong?

Evidently, perhaps some more details about how you've initialized things, and how they are connected.

You probably want

while( USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);

if you want it to spin while NOT asserted

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
developer2
Senior
Posted on August 07, 2013 at 19:00

did you set USART mode:

 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

 and both USART GPIO pins as AF ?

timothy
Associate II
Posted on August 07, 2013 at 20:40

GPIO_InitTypeDef GPIO_InitStructure; // GPIO structure
USART_InitTypeDef USART_InitStructure; // USART Structure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Configure USART Tx as alternate function push/pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA9-UART.TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// USART Configure
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_Parity = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_Parity_No;
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);

Here is how i initialized everything. After further testing it works once and stops. while( USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) { do stuff} Any ideas why it would stop? the do stuff mentioned here works already im just trying to have it work only when USART is receiving data.
Posted on August 07, 2013 at 21:42

Don't enable the RXNE interrupt.

If you're using an interrupt, you a) need to initialize NVIC also, and b) have a service routine to handle it.

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