Skip to main content
Visitor II
April 15, 2008
Question

str9 UART

  • April 15, 2008
  • 7 replies
  • 1177 views
Posted on April 15, 2008 at 05:59

str9 UART

    This topic has been closed for replies.

    7 replies

    s_bhujbalAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:52

    Dear All,

    I am using UART0 of STR9, I am abled to transmit the data to PC. I have made one simple function which takes string as input & transmits data byte by byte on UART with help of ST library function UART_SendData().

    When I calls that function through while( 1 ), it gives junk chars on PC. Other every thing is right i.e. baud rate & other parameters on both ends. I tried to check busy flag to let UART transmit data completely, I have also tried other flags also like FIFO Empty/Full flag, but still it is giving junk chars at PC end.

    I will be very thankful if anybody tell me the solution.

    :-[

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:52

    are you FIFOs working?

    s_bhujbalAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:52

    Yes FIFOs are enabled

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:52

    ''Garbage characters'' is usually a sign of a mismatch in baud rates or word size. Are you sure the clock source is at the frequency you think it is?

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:52

    post your register values please.

    s_bhujbalAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:52

    Dear Michael & JakBird Thanks for replying,

    I am using Library given by ST. If I print string through before while it gets on PC properly therefore I think that baud rate setting is not problem. My code is as follows after configuring PLL for 96MHz.

    /* Enable the UART0 Clock */

    SCU_APBPeriphClockConfig(__UART0, ENABLE);

    /* UART Initialization */

    UART_InitStructure.UART_WordLength = UART_WordLength_8D;

    UART_InitStructure.UART_StopBits = UART_StopBits_1;

    UART_InitStructure.UART_Parity = UART_Parity_No ;

    UART_InitStructure.UART_BaudRate = 9600;

    UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;

    UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;

    UART_InitStructure.UART_FIFO = UART_FIFO_Enable;

    UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

    UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

    UART_DeInit(UART0);

    UART_Init(UART0, &UART_InitStructure);

    /* Enable the UART0 */

    UART_Cmd(UART0, ENABLE);

    /* Following is the code in main */

    sprintf( acString,''Any String'');

    Uart0printf( acString ); <----This line works properly

    while ( 1 )

    {

    Uart0printf( acString ); <----This line doesn't work properly

    }

    Following is the function which I am using for printing a string

    void Uart0printf( char *pcString )

    {

    while( *pcString != '\n' )

    {

    UART_SendData( UART0, *pcString);

    while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) != RESET);

    At above position I have also tried some other flags & there SET, RESET values, even UART_Clear function also used

    pcString++;

    }//while

    }//Uart0printf

    Please tell me if any mistake in above code.

    s_bhujbalAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:52

    Dear All,

    Problem is solved. Mistake was in checking '\n' in place of NULL. After correcting it I just added ''while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) != RESET);'' after char send API. Now it is working fine in while also.

    Thanks

    :D