AnsweredAssumed Answered

UART4 Rx

Question asked by vivek on Sep 10, 2012
Latest reply on Sep 10, 2012 by Clive One
Hello every1,
few days ago i had a problem with uart tx and nw i have solved that problem. so my tx is working fine now. my rx is working too but very slow and gets junk values. below is my code.
int main(void)
{
  /* GPIOC clock enable */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  /* USART4 clock enable */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); 

  GPIO_InitTypeDef GPIO_InitStructure;
    
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_UART4);/* UART4_TX */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_UART4);/* UART4_RX */

  /*-------------------------- GPIO Configuration ----------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

    USART_InitTypeDef USART_InitStructure;
//    USART_ClockInitTypeDef USART_ClockInitStruct;
  /* USARTx configuration ------------------------------------------------------*/
  /* USARTx configured as follow:
        - BaudRate = 9600 baud
        - Word Length = 8 Bits
        - Two Stop Bit
        - Odd parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
    USART_InitStructure.USART_BaudRate = 9600;  //115200;
  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(UART4,&USART_InitStructure);  //uart

    USART_Cmd(UART4, ENABLE);

  while (1)
  {    
            if (USART_GetFlagStatus(UART4, USART_FLAG_RXNE) != RESET)
     {
       uint16_t x = USART_ReceiveData(UART4);
 
       while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET);
 
       USART_SendData(UART4, x);
     }

}


As u can see im trying to loop back whatever data i receive. Im using STM32F4-Discovery board with STM32F407VGT6 IC. any help wud be much appreciated.


Vivek


Outcomes