Reproduced on: RS232, RS485 Waveform Analysis
I often encounter problems with single-chip serial communication for beginners and do not know how to do it. In fact, the most effective debugging method is to use an oscilloscope to observe the waveforms of the sent and received data. Observe the waveform to determine the following situations:
- Whether data is received or sent
- Is the Data correct?
- Whether the baud rate is correct
1. Serial Data Format
The general format of asynchronous serial data is: start bit + Data bit + stop bit, where start bit 1 bit, data bit can be 5, 6, 7, 8, the stop position can be 1, 1.5, or 2.
The Start bit is a bit with a value of 0, so for the TTL level of positive logic, the start bit is a low level of time; the stop bit is a bit with a value of 1, therefore, for the positive logic TTL level, the stop bit is a high level. The line is idle or the data transmission ends. For the TTL level of the positive logic, the line is always 1. The opposite is true for negative logic, such as RS-232 levels.
For example, for hexadecimal data 55aah, when 8-Bit Data bit, 1-bit stop bit transmission, its waveform 1 (TTL level) on the signal line and figure 2 (RS-232 level. (First pass the first byte 55, then the second byte AA, each byte is transmitted from low to high bit by bit)
Figure 1 TTL-level serial data frame format (55aah)
Figure 2 serial data frame format (55aah) for RS-232 level)
2. Calculate the baud rate based on the waveform
3 is the diagram 1 shown in the oscilloscope, where the gray line is the time discrimination line of the oscilloscope, which is assumed to be 200us/grid.
Figure 3 baud rate calculation
You can see that the first byte's 10-bit (one-bit start bit, eight-Bit Data bit and one-bit stop bit) accounted for about 1.05 ms, so that the baud rate is calculated as follows:
10bit/1.05 Ms x 1000 ≈ 9600 bit/s
If the timeline is US/grid, the baud rate can also be calculated as bit/s.
When the communication is abnormal and the waveform can be observed, you can calculate whether the baud rate is correct from the waveform chart based on the above method.
3. judge whether the RS-485 sends and receives data correctly based on the waveform chart
RS-485 is a half duplex serial communication mode (RS-422 for full duplex), 485 level chip so to correctly receive and send data, must ensure control signal and data synchronization, otherwise, either the sent data is lost or the received data may be lost. The correct timing 4 when the RS-485 sends data is shown.
Figure 4 Timing of correct data transmission for a RS-485
In Figure 4, the width of the sending control signal is basically the same as that of the data signal, so it can ensure that the sent data is correct and converted to the received data in a timely manner after being sent.
Figure 5 and figure 6 show that the control signal is too short and the control signal is too long.
Figure 5 Timing of the RS-485 control signal too short
Figure 6 Timing of RS-485 control signal too long
In Figure 5, because the control signal is too early to close, the last two digits of the second byte will send an error. In Figure 6, because the control signal is too late to close, after the 485 Chip sends data, it cannot be transferred to the receiving status in time. If the BUS receives data, the unit cannot receive the data correctly.
Conclusion: As long as you master the above waveform analysis method, the problem of receiving and sending asynchronous serial data can be basically solved.
RS232 and RS485 Timing Analysis