Design of MSP430 MCU Application System Based on I2C Bus

Serial protection bus technology is a notable feature of the new generation of microcontroller technology development. Among them, the I2C bus introduced by PHILIPS is the most famous. It includes an interface at both ends. Through an interface with a buffer, data can be sent or received by I2C, and control and status information is transmitted through a set of memory-mapped registers. Compared with the parallel expansion bus, the serial expansion bus has outstanding advantages: the circuit structure is simple, the program writing is convenient, and it is easy to realize the modularization and standardization of the software and hardware of the user system. This article is a typical example of applying I2C bus to the temperature control system of MSP430 microcontroller.

Serial protection bus technology is a notable feature of the new generation of microcontroller technology development. Among them, the I2C bus introduced by PHILIPS is the most famous. It includes an interface at both ends. Through an interface with a buffer, data can be sent or received by I2C, and control and status information is transmitted through a set of memory-mapped registers. Compared with the parallel expansion bus, the serial expansion bus has outstanding advantages: the circuit structure is simple, the program writing is convenient, and it is easy to realize the modularization and standardization of the software and hardware of the user system. This article is a typical example of applying I2C bus to the temperature control system of MSP430 microcontroller.

The I2C bus uses two bidirectional I/O signal lines (serial clock line SCL and serial data line SDA) to connect various devices and realize serial communication between devices.

MSP430 is a powerful 16-bit microcontroller with ultra-low power consumption from TI, and MSP430F169 is a model in this series. It integrates 2 16-bit timers, 1 high-speed 12-bit A/D converter, 12-bit or 8-bit double D/A converter, 2 universal synchronous/asynchronous communication interfaces and 1 I2C module. We just use its I2C module to expand the MSP430F169 microcontroller.

System Hardware Design

The system realizes temperature control for the heat treatment of the crankshaft. The heat treatment process of the crankshaft is as follows: the crankshaft is placed in a quenching furnace for heating at 350℃~400℃/h, kept at 910℃~930℃ for 1.5h, quenched and cooled to room temperature, and then tempered at 550℃-600℃ for 2.5h in the furnace. Therefore, the system requires simultaneous temperature control of the quenching furnace and the tempering furnace. In this system, we need to design the keyboard module and LED Display module respectively, realize the manual input setting of temperature, PID parameters, time period and other parameters through the keyboard, and display the temperature of the quenching furnace and the tempering furnace in real time through the LED. In the past single-chip microcomputer application system, the keyboard interface and LED display interface are generally extended through the parallel bus, which is characterized by fast information transmission, but it occupies many ports and the circuit is complicated. With I2C BUS, the system can be expanded through I2CBUS. At this time, as long as the SCL and SDA signal lines are used to connect the single-chip microcomputer with the peripheral devices, the occupied signal lines are less and the circuit is greatly simplified. The system circuit structure is shown in the figure. 1 shown.

Design of MSP430 MCU Application System Based on I2C Bus
Figure 1 System hardware circuit diagram

The keyboard interface in the figure is extended by PCF8574, which is an 8-bit I/O expander with 8-bit quasi-bidirectional port and I2C bus interface. Each bit can be individually set as input or output, low power consumption, and the output is latched , strong driving ability, and also has the function of interrupt request. In this scheme, the chip is used as a 4×4 matrix keyboard to interface with the single-chip microcomputer. After initialization, P0-P3 is the output low level, and P4-P7 is the input. Usually the single-chip microcomputer executes other programs. When any key is pressed, the chip An interrupt request signal is generated at the INT end, and the CPU responds to the interrupt and enters the interrupt service routine.

In this chip, A2-A0 is the address pin, which is determined by the pin level. In this system, A0 is connected to a high level, and A1 and A2 are grounded; P0-P7 is a quasi-bidirectional port; INT is the interrupt request output, low The level is active, it should be noted that this terminal should be pulled up through a pull-up resistor. When the single-chip master node writes a byte to the PCF8574, the data output of the I/O port is realized. The serial data sent by the I2C bus to the PCF8574 appears on the I/O port after the response bit, the I2C bus keeps sending the numbers, and the data on the I/O keeps changing. When the master node of the microcontroller reads the PCF8574, the data input of the I/O port can be realized, and the read data is stored in the receiving buffer MRD. When the level state of the input terminal of PCF8574 changes, the interrupt request output terminal INT appears low level, and the interrupt output is valid. After the read and write operations on it, the interrupt request is reset. The input operation of the I2C bus to the PCF8574 I/O port is a read operation of a byte. The SLAW/SLAR of the PCF8574 in this system is 42H/43H.

The SAA1064 in the figure is a 4-bit seven-segment LED display driver circuit with a decimal point. The device can statically drive 2-bit LEDs and dynamically drive 4-bit LEDs. There is only one address pin ADR, but 4 levels of states can be selected. There is a dynamic drive control circuit in SAA1064, and no external dynamic drive management is required. In this chip, ADR is the address pin, and 4 analog level states correspond to 4 pin addresses; CEXT is the external capacitor of the clock oscillator, with a typical value of 2.7nF; P1-P16 are the segment drive output ports, which are locked. When the register is set to 1, the port state is low level; MX1 and MX2 are in the dynamic display mode, the common segment drives the output terminal, and the external application drives the transistor. The device address of SAA1064 is 0111, and there is only one address pin, namely ADR. The pin addresses A2, A1, and A0 adopt ADR analog level comparison addressing. The ADR pin levels are 0, 3/8VDD, 5/8VDD, When VDD, the corresponding pin addresses A2, A1, A0 are 000, 001, 010, 011.

In this system, one of the ADRs of the two SAA1064s is grounded and the other is connected to VDD. According to the connection method in the figure, the SLAW/SLAR of the left SAA1064 is 70H/71H, and the SLAW/SLAR of the right SAA1064 is 76H/77H. The dynamic driving method is used to connect 3 LEDs on the two SAA1064s respectively, and the P1-P8 ports are used to dynamically drive the two-digit LED display, and the P9-P16 ports individually drive the one-digit LED display. There are 5 register units in SAA1064, which are 1 control register and 4 display registers respectively. The loading content of address unit 00H is control command COM, and the loading content of address unit 01H, 02H, 03H and 04H is display segment code 1, Display segment code 2, display segment code 3, and display segment code 4. In this system, only the first 3 display segment codes are used. The one-chip computer can read the status byte from the chip, and this status byte only uses the highest bit PR. PR=1 indicates that there has been a power-down and power-on since the last read status. After reading the status byte, PR is cleared to “0”. The single-chip microcomputer can also write address bytes, instruction bytes, control bytes and data bytes to the chip. SC, SB, SA in the instruction byte (00000SC SBSA) specify which unit the data byte after the instruction byte starts from. Write, the address will be automatically incremented later.

System software design

The I2C controller in MSP430F169 is a part of the universal serial synchronous/asynchronous USART peripheral module, and only has the I2C mode in USART0, and the definition of its individual bits is different from the SPI or UART mode. The default value of the U0CTL register is UART mode. The register contains the following bits: the SYNC bit must be set to select the SPI or I2C mode. When SWRST=1, set the SYNC bit to select the SPI mode. When SYNC=1, set the I2C bit to select the I2C mode. For USART0, the SYNC bit and the I2C bit can be set simultaneously in one instruction to operate in I2C mode.

Design of MSP430 MCU Application System Based on I2C Bus
Figure 2 Flowchart of the main sending program

The I2C module inside the MSP430F169 can operate in the master sending, master receiving, slave sending or slave receiving mode. This application system is a single master system, so the microcontroller only operates in the master sending and master receiving modes. The registers used to manage the I2C bus in the MSP430F169 microcontroller are: interrupt enable register I2CIE, interrupt flag register I2CIFG, data volume register I2CNDAT, universal serial synchronous/asynchronous module register U0CTL, transmission control register I2CTCTL, data control register I2CDCTL, frequency division Counting register I2CPSC, clock high level register I2CSCLH, clock low level register I2CSCLL, data register I2CDR, master address register I2COA, slave address register I2CSA, interrupt vector register I2CIV. In the main operation mode, the sending and receiving operations are mainly controlled by the three bits I2CRM, I2CSTT, and I2CSTP. These three bits are all bits in the transmit control register I2CTCTL, where I2CRM is the cyclic repetition mode control bit, which is 0. The number of bytes sent is defined by I2CNDAT. If it is 1, it means that the number of bytes sent is controlled by software, and is not used by I2CNDAT.

I2CSTT is the start transmission control bit, which is set to 1 to start data transmission. Once the data transmission starts, this bit is automatically cleared. I2CSTP is a stop transmission control bit. This bit is 1 to stop data transmission. Once data transmission is stopped, this bit is automatically cleared. In the master transmit mode, once the slave address byte and the read/write direction bit are sent, the master receive mode can be entered by setting I2CTRX=0. The flow chart of the main sending program is shown in Figure 2, and the flow chart of the main receiving program is shown in Figure 3.

Design of MSP430 MCU Application System Based on I2C Bus
Figure 3 Flowchart of the main receiving program

Epilogue

Because the I2C bus technology is introduced into the system design, the hardware circuit of the system becomes very simple. At the same time, the new 16-bit microprocessor MSP430F169 is used to form the core of the entire control system. Because of its own I2C interface, the software programming of the system is also It is relatively simple, so it can be regarded as a good system design scheme.

The Links:   MG15D6EM1 CM400DU-24NFH

Related Posts