AnsweredAssumed Answered

UART baud rate issues

Question asked by vinod Karuvat on Mar 23, 2014
Latest reply on Mar 23, 2014 by vinod Karuvat

Hello Friends,

 

I have been trying to ping my PC (hyper terminal) from the UART. I want to ping it at 9600 baud. I have given the BDH:BDL = 0x222 = 506 (in decimal). The clock is from MCGFLLCLK and I have no pre scalers associated with it. So its at 20.97MH (default value). So, i deally must configure the hyper terminal at 9600 baud. When done it shows garbage. Then i lowered the hyperterminal baud upto 2400 or so and got all the data perfectly. So , it seems I am configuring the UART to 2400 baud by some wrong method. Where am I making.The code is pasted below. Kindly assist me out

 

//UART - configured - 9600, hyperterminal - configure for 2400 !!!!!

 

/*

* main implementation: use this 'C' sample to create your own application

*

*/

 

 

// selected baud - 9600 //

// hyper terminal - 2400 baud for FRDM board !!!!!!!! //

#include "derivative.h" /* include peripheral declarations */

 

int main(void)

{

        int tempCount,tempCount2 = 0;

        short int c;

                // clocking //

        SIM_SOPT2 |= 0x01000000;      // clock sel for the timer0 //

        SIM_SCGC5 |= 0x00000400;          // gating of clock //

        SIM_SCGC6 |= 0x01000000;      // gating of timer //

        SIM_SOPT2 |= SIM_SOPT2_UART0SRC(1);

                SIM_SCGC4 = SIM_SCGC4_UART0_MASK;

                SIM_SCGC5 = SIM_SCGC5_PORTB_MASK;

 

                PORTB_PCR2 = PORT_PCR_ISF_MASK|PORT_PCR_MUX(2);

                PORTB_PCR1 = PORT_PCR_ISF_MASK|PORT_PCR_MUX(2);

                UART0_C2 &= ~ (UART0_C2_TE_MASK| UART0_C2_RE_MASK);

 

        PORTB_PCR8 |= 0x00000100;    // alternative pin mux selection //

        GPIOB_PDDR |= 0x00000100;    // pin direction //

 

                UART0_BDH = 0x02;

                UART0_BDL = 0x22;

                UART0_C4 = 0x0F;

 

                UART0_C1 = 0x00;

                UART0_C3 = 0x00;

                UART0_MA1 = 0x00;

                UART0_MA1 = 0x00;

                UART0_S1 |= 0x1F;

                UART0_S2 |= 0xC0;

 

                UART0_C2 |= UART0_C2_TE_MASK| UART0_C2_RE_MASK;

 

                while (1)

                {

                        //#if UART_MODE == POLLING_MODE

                                while(!(UART0_S1&UART0_S1_RDRF_MASK));

                                        c = UART0_D;

                                while(!(UART0_S1&UART0_S1_TDRE_MASK) && !(UART0_S1&UART0_S1_TC_MASK));

                                        UART0_D = c;

                        //#endif

                }

        }

 

 

 

Vinod

Outcomes