Concepts such as serial port baud rate

Part I: the baud rate and other concepts

1: bit rate: 9600bps

Is transmitted per second 9600bit, which is equivalent to every second division in 9600 became equal parts.

So, the time per 1bit is 1/9600 seconds = 104.16666666666666666666666666667us. About 0.1ms. Since 9600 is equal parts, i.e., a bit in each 1bit Then, no extra space is present. And no matter what the starting bit, data bit, parity bit, stop bit.

2: frame format, frame interval.

In the computer, which is super-terminals and other port settings. The default settings of the computer port, which is default frame format is: 8 data bit, 1 stop 'bit, (1bit start is necessary) default no parity, no flow control.

It is in fact a 10bit to a. 9600 may be sent in one second / 10 = 960 frames, that is 960 characters, since there is only a 1 character, a character is inside the frame 8 data bit

3: serial communication

Serial continuous course, no transmission frame time interval, the computer may send a default case 960 at 9600bps.

But in practice, in asynchronous communication, generally requires an interactive process, so the computer sends a frame or several frames, also need to wait for a response from the device, not been sent. Youwenyouda to achieve the objectives of the programmer.

4: Baud Rate Clock

Actually the bit rate clock, the time period to be spent per 1bit. The baud rate (actually the bit rate) divided clock generator generates a clock actually sampled every 1bit, which is 16 times the baud clock.

 Essence of a baud rate generator is a frequency divider design for clock generation and synchronization RS232 communication. In the system using a counter to accomplish this function, the frequency division factor N determined baud rate value. The counter is typically operated at a higher frequency of the system clock, when the count N / 2 output is set high, then the count output is set to a value after N / 2 is low, and so forth can be to give 50% duty cycle clock baud rate, the baud rate depends on the particular system clock frequency used and the size N. The system clock frequency is 40MHz, the baud rate is required 9 600 [MS1], is 16 times the baud rate clock 260 is approximately equal to the period of the system clock cycle, the fetch counter 260/2 = 130, the output when the counter overflows level inverted clock can be obtained 16 times the baud rate agreed.

(Liupeng)

It can be also understood that: 40mhz crystal, the minimum count pulse is 25ns, the frequency of 16 times the baud rate is 9600 * 16, which clock cycle is 1 / (16 * 9600) = 6.5us 40mhz crystal as it is entered, the counter need count = 6500/25 = 260 counts.

Also be understood as a baud rate of 9600 baud clock frequency, i.e., 1 second count 9600, if the clock is 16 times the baud rate, i.e. multiplied directly on it. Second counter is 9600 * 16 = 153600.

1 / (9600 * 16) divided by (1/40000000) it is not only the number of clock cycles the minimum clock period is obtained count. For simplification is 40000000 / (16 * 9600) = 260, the frequency is divided directly to get the frequency division number of the counter.


[MS1]

40000000/(9600*16)=260.4

Must be set to the serial communication baud rate, the baud rate for this design uses 9 600bit / s. Generating a clock frequency of the baud rate is the higher the better, and this way can produce higher accurate baud rate. 50M design uses a primary frequency to be generated 9600bit / s baud rate, one bit of data per clock cycle requires 5208.33. Take a nearest number is 5208, then the baud rate is 9600.61, the error is about 0.006%, the error rate is very low normal communication can be ensured.

(Liupeng 50000000/5208 = 9600.61)

5: an error allowable range

6: frequency division factor

Counter easy to implement divider. Available lpm-counter implementation.

Such division factor is 2, then, can be directly used as the output q0. If the division factor is 4, then q0, q1 as an effective bit.

Sum, n is an integer division, i.e., re-counting the count n is cleared. As for the 50% duty cycle is another consideration. Odd division seems easy to achieve a 50% duty cycle.

Part II: How to identify the serial port baud rate you?

     UART serial port, most commonly used as a single-chip communication interface has gone deep mind every embedded engineers. [Www.t262.com) UART serial port with simple, practical features, embedded engineers often used it as an important tool for debugging system. UART serial port configuration parameters are many, but the most common, and only need to modify the parameters of the communication baud rate of this one. But this is only one parameter and often brought us a lot of trouble. So, how do we recognize it for the serial port baud rate? Here the author describes three methods to identify serial rate, for your reference.

    UART (Universal Asynchronous serial Receiver and Transmitter) serial asynchronous receive / transmit port, one of the most important interface embedded systems, not only for communication between a chip board, and the communication between the system used to achieve and scheduling system. UART is an asynchronous serial communication protocol A, works each character transmitted data bit by bit transmission, the character data frame format as shown below:

How baud serial port baud rate recognition you?

    FIG 1 UART frame format character data

    As can be seen in the above frame format of FIG, UART data frame synchronization bits of a beginning, a data word, one end of the stop bit, and an optional parity bits. Since the UART is asynchronous communication, therefore, it must be strictly observed baud rate setting when sending bit, but the recipient must parse character data sent to the right at the same baud rate. Thus, the recipient correctly identified, the baud rate configuration is quite critical. Here the author describes three methods to identify the baud rate based on practical experience:

    Exhaustive method

    Theoretically, the transmission baud rate can be set to any value, but usually we use only so few serial rate value, shown in Figure 2:

How baud serial port baud rate recognition you?

    FIG 2 common serial baud rate

    Now that the common serial port speed, so we can try one by one, there will always be a success. Of course, only if we know what is sent by the host, otherwise how can we know the correct serial port speed to match it be noted here that in the case of setting the baud rate and actual baud rate is a multiple of the data can be read out! - of course, the data is wrong.

    Oscilloscope law

    The oscilloscope is an electronic engineer seconds "eyes", we will use those eyes to "see" the baud serial port to send data. Here we exclude the first oscilloscope with digital logic analysis function off high-end, because such scope is already far more than the author's IQ, is not what we Benpian discussion.

    A part, we describe the waveform of frame format, here we use a waveform, sends a special character 0x55 (1010 1010B). From the above analysis theory, this should produce a waveform bit-flip wave effect. FIG 3 is the author of the oscilloscope to capture a screenshot down:

How baud serial port baud rate recognition you?

    FIG 3 9600bps transmission waveform diagram 0x55

    See the waveform shown in FIG. 3, together with theoretical analysis, we know that the waveform is inverted bit, so we use the function pointer oscilloscope (Cursor) to directly view the baud rate. The upper left corner in FIG. 3 show the measurement results, the frequency of each flip 9.615KHz, substantially in line with our 9600kbps set frequency, this may be determined transmission frequency of 9600bps.

 

  Since the chip identification method

    Often used as UART serial interface used by the firmware upgrade, so that the baud rate according to the actual situation to the host computer. If the environment is poor, we need to use low baud rate of communication. At this time, the automatic baud rate detection method was born. Here we have TI Stellaris serial port baud rate in the bootloader in the automatic identification of source code example for analysis:

    int UARTAutoBaud(unsigned long *pulRatio){

    long lPulse, lValidPulses,LTEmp, lTotal;

    volatile long lDelay;

    // configuration systICk, its value is set to the maximum;

    HWREG(NVIC_ST_RELOAD) = 0xffffffff;

    HWREG(NVIC_ST_CTRL) = NVIC_ST_CTRL_CLK_SRC| NVIC_ST_CTRL_ENABLE;

    // open edge triggered interrupt pin

    HWREG(GPIO_PORTA_BASE + GPIO_O_IBE) = UART_RX;

    // Enable UART RXD pin edge-triggered interrupts

    HWREG(NVIC_EN0) = 1;

    // edge interrupt collecting pins, two bytes edge

    while(g_ulTickIndex < MIN_EDGE_COUNT)

    {

    }

    // Calcd systick down sampling, processing overflow

    for(lPulse = 0; lPulse < (MIN_EDGE_COUNT - 1); lPulse++){

    lTemp = (((long)g_pulDataBuffer[lPulse] -

    (long)g_pulDataBuffer[lPulse + 1]) & 0x00ffffff);

    g_pulDataBuffer[lPulse] = lTemp;

    }

    // This cycle calculates the width between two consecutive pulses

    for(lPulse = 0; lPulse < (MIN_EDGE_COUNT - 1); lPulse++){

    // accurate calculation of the width between two consecutive pulses

    lTemp = (long)g_pulDataBuffer[lPulse];

    lTemp -= (long)g_pulDataBuffer[lPulse + 1];

    if(lTemp < 0) {

    lTemp *= -1;

    }

    // verify correct both edges of the pulse width, the algorithm is as follows:

    // ABS (Pulse [n] - Pulse [n + 1]) <Pulse [n + 1] / PULSE_DETECTION_MULT

    // or

    // PULSE_DETECTION_MULT * abs (Pulse [n] - Pulse [n + 1]) <Pulse [n + 1]

    if((lTemp * PULSE_DETECTION_MULT) < (long)g_pulDataBuffer[lPulse + 1]) {

    lTotal += (long)g_pulDataBuffer[lPulse];

    lValidPulses++;

    }

    else{

    lValidPulses = 0;

    lTotal = 0;

    }

    // 7 effective pulses may be calculated UART serial rate

    if(lValidPulses == 7) {

    // will finally join a pulse counter, and calculate the baud rate

    lTotal += (long)g_pulDataBuffer[lPulse];

    *pulRatio = lTotal >> 1;

    // return success identification

    return(0);

    }

    }

    // test failure

    return(-1);

    }

    UART serial port has the advantage one way or another, but the emerging USB DFU function USB interface can be more effective alternative to the serial port to complete the firmware upgrade; superior performance of CAN bus, its hardware prices continue to decline, and MAC interface CAN bus is more integrated in the latest MCU chip; CAN2.0B interfaces are squeezing the market UART interface device; for us ordinary people, and now the new computer models have no serial DB9 seat. In the harsh reality, perhaps only after many years of our electronic engineers will remember the simple, practical UART serial port.

Guess you like

Origin blog.csdn.net/luoyajingfeng2/article/details/83338499