Remote communication between MSP430 and PC and LCD display
[Copy link]
Overview In the microcomputer measurement and control system, information exchange is often carried out between the PC system used as the upper computer and the single-chip microcomputer used as the lower computer. The current mainstream single-chip microcomputer and PC are both equipped with serial ports, so the communication between the two can be completed through the serial port. However, in actual applications, the main control PC and the single-chip microcomputer are sometimes far apart. In order to ensure that the data can be transmitted to the PC in a timely and safe manner at high speed, it is more reasonable to use the RS485 protocol serial communication between the single-chip microcomputer and the PC. In order to meet the needs of real-time communication, we make the interface circuit full-duplex. In practical applications, it is necessary to display some digital quantities transmitted from the PC to the microcontroller. For the MSP430 microcontroller, the LCD display module is the most suitable. It can process the quantity transmitted remotely by the serial port and then use the LCD to display it in real time. This has a large application space in real life. TI's MSP430 series microcontroller is an ultra-low power mixed signal controller, which includes a series of devices, which are composed of different modules for different applications. In the MSP430A series microcontroller, the LCD driver exists as an on-chip module in the MSP430F4XX and MSPX3XX series devices. Using this feature, the data to be transmitted by the PC can be directly displayed under the LCD module drive of the MSP430 series microcontroller. Hardware Design Design of 485 serial communication interface circuit In practical applications, since most ordinary PCs and MCUs only have the commonly used RS232 serial communication port, but not the RS485 communication interface, in order to realize the serial communication of RS485 protocol, the conversion between RS485 and RS232 must be configured on the PC side. The block diagram of the overall hardware interface circuit of RS485 communication between MCU and PC is shown in Figure 1. Figure 1 Block diagram of the overall RS485 communication hardware interface circuit | Design of interface circuit on MCU side The MAX490 in Figure 2 is the RS485 interface chip of MAXIM, and its internal structure is shown in Figure 3. MAX490 supports single power supply +5V operation and can realize full-duplex communication. The level standards of R0 and D0 are as follows: logic "0" is between 0.5V and 0.8V, and logic "1" is between 2.0V and Vcc. The working state is: when the voltage of terminal A is higher than the voltage of terminal B by more than 200mV, R0 outputs logic "1", and when the voltage of terminal A is lower than the voltage of terminal B by 200mV, R0 outputs logic "0"; when DI inputs logic "0", Y outputs low and Z outputs high, otherwise Y outputs high and Z outputs low. Figure 2 MCU side interface circuit | The URXD and UTXD levels of the MSP430 serial communication module of the single-chip microcomputer comply with the TTL/CMOS standard. When the RXMCU of the PC has a level input, it first passes through the 6N137 photoelectric isolation to protect the single-chip microcomputer from interference, and is output from the O pin to the DI, thereby being converted into the RS485 level and output by Y and Z. Conversely, the output signal of the PC is converted into the input of the A and B terminals of the MAX490, and first converted to the R0 output, and then finally output by the TXMCU after photoelectric isolation. PC side interface circuit design The specific implementation of the PC side circuit is shown in Figure 3. The RS232 level standard is as follows: the level range of logic "0" is 5V-15V, and the level range of logic "1" is 5V-15V. The MAX232A selected here is the RS232 level conversion chip of MAXIM. When the PC's TXDPC is output to R1IN, it is first converted into TTL level by MAX232A and output by R1OUT, and then input into the DI pin after being optically isolated by 6N137, and then converted into RS485 level and output by Z and Y. Similarly, the RS485 level signal converted from the microcontroller output signal is input to the A and B pins, converted to TTL level by MAX490, and finally output by RXDPC after optical isolation. It must be emphasized that in the circuit connection, the MAX490 chip pins RSOUT+ and RSOUT- in the PC side interface circuit must be staggered and connected to the MAX490 chip pins RSIN+ and RSIN- on the microcontroller side in pairs, so that normal communication can be achieved. Figure 3 PC side interface circuit | LCD driver and display circuit design In the system, we need to display some key digital quantities in the information sent by the PC to the microcontroller. For the MSP430 microcontroller, the use of LCD display module is the most appropriate. The quantity transmitted remotely by the serial port can be processed and then displayed intuitively in real time with LCD. This has a strong application space in real life. The LCD mentioned here does not have any driving circuit, so we can further customize the LCD block ourselves, and theoretically can display any information. The control/driving of the LCD on the MSP430A device will simplify the display of the LCD. Different models have different LCD driving capabilities. In the design, we use the 41X series of MSP430, which has a 96-segment driving capability. There are four ways to drive the LCD: static, 2MUX or 1/2 duty cycle, 3MUX or 1/3 duty cycle, 4MUX or 1/4 duty cycle. The driving principle and control method are the same for different series and models of LCDs. The difference lies in the different number of LCD segments driven or the amount of information that can be displayed. In the experiment, we use 4MUX. Figure 4 shows the overview of the MSP430 LCD driver module.
Figure 4 Connection between MSP430 LCD driver module and LCD | There are two points to note: (1) Liquid crystal bias. Since the liquid crystal driver uses AC voltage, the bias must be set according to the working mode of the liquid crystal. The specific operation is: in STATIC mode, R33 is open and R03-R23 are grounded. In 2MUX mode, 10K resistors are connected between R33, R13, and R13 and R03 respectively; in 3/4MUX mode, 10K resistors are connected between R33 and R23, R23 and R13, and R13 and R03 respectively. This ensures that the voltage supplied to the liquid crystal block from COM0-COM3 meets the requirements, as shown in Figure 5.
Figure 5 Voltage waveform of COM port in MUX4 mode | (2) Frequency setting. MSP430 has three clocks: ACLK (auxiliary clock), MCLK (master clock), and SMCLK (sub-clock). The LCD driving frequency FCLK comes from ACLK. A crystal oscillator with an oscillation frequency of 32KHz is connected between XTIN and XTOUT. Fclk can be selected as 1024Hz, 512Hz, 256Hz, 128Hz, etc. as needed. The settings of FRFQ0 and FRFQ1 can meet the frequency requirements of different LCDs, where Flcd=2*MUX(rate)*F(framing). For example: using 3MUX, it is known that F(framing)=100Hz-30Hz, From F(LCD)=2*MUX(rate)*F(framing)=6*F(framing), It can be seen that F(LCD)=180Hz-600Hz. The selectable F(LCD) is 1024Hz, 512Hz, 256Hz, 128Hz, so F(LCD)=32K/128=256Hz, so FRFQ0=1, FRFQ1=0. On the basis of the above two points, we only need to output the code corresponding to the number to be output to the video memory of MSP430 to display it. If the liquid crystal shakes in the experiment, the driving frequency of the liquid crystal can be appropriately increased. If the brightness of the liquid crystal is not enough, the size of the bias resistor should be appropriately adjusted. Software Design Principle and programming method of serial communication of single chip microcomputer The debugging of the MCU software is completed by using a PC, an emulator, and the IAR ICE integrated development environment. The communication on the MCU side can be done in serial interrupt mode or query mode. In the process of implementing the MCU software, the following requirements are required: (1) serial port communication settings (2) serial port mode selection (3) selection of a suitable baud rate. In the experiment, we uniformly use the query mode. VC Serial Communication and Programming Method of PC Using ActiveX control (MScomm control) programming, the advanced ActiveX technology of Windows platform makes serial port programming easier. With the existing ActiveX control, you only need to write a small amount of code to complete the task easily and efficiently. Microsoft Communications Control (hereinafter referred to as MSComm) is an ActiveX control provided by Microsoft to simplify serial communication programming under Windows. It provides a simple way for applications to send and receive data through serial interfaces. Conclusion The above hardware circuit can realize serial communication in accordance with RS485 protocol, and can display the digital quantity of interest on LCD. The system has completed the experimental test. If the hardware and software are designed reasonably, the reliability is further improved, and the full-duplex remote communication and LCD display functions are added, it is believed that it can have a wider range of practical applications.
|