cancel
Showing results for 
Search instead for 
Did you mean: 

UART4 Rx

vivek2
Associate II
Posted on September 10, 2012 at 04:03

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

#wait-for-you--clive1-!-!-! #wait-for-you--clive1-!-!-! #wait-for-you--clive1-!-!-!
4 REPLIES 4
vinothraj
Associate II
Posted on September 10, 2012 at 06:40

uint8_t bc;

while

{

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

bc = (USART_ReceiveData(UART4) & 0x7F); 

while (USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET);

              

USART_SendData(UART4, bc);

}

vivek2
Associate II
Posted on September 10, 2012 at 07:50

thnx vinoth!

i found the problem. it was my interface ic.

i was then trying to read a text file(40 KB) using hyperterminal. I can read a part of the file perfectly(say 15-20 lines) and some part is not captured(say 40-50 lines) n so on. my code remains the same as above.

vivek2
Associate II
Posted on September 10, 2012 at 07:51

Posted on September 10, 2012 at 15:50

I think, ideally, you want to add some buffering to provide elasticity between the rate the data comes in and the rate it leaves.

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