Вы находитесь на странице: 1из 7

Communication Design for I2C Bus Based on Proteus

Fengjie Wu1, Liming Wu2, and Tangmei He1


Laboratory Center of Guangzhou University, Guangzhou in China Information Engineering School of Guangdong University of Technology, Guangzhou in China wufengjie501@163.com, {liming0118,385357885}@qq.com
2 1

Abstract. We introduce Proteus virtual development techniques into the microcontroller I2C bus communication designs, and take the AT24C02 for example to explain the Proteus simulation software and hardware design circuit of I2C bus communication. Then we analyse the hardware and software problem in Proteus debugging and provide the solution. The Simulation results which is identical with theoretical analysis prove that the correctness and the accuracy of Proteus virtual simulation. It has very important significance in the microcontroller virtual development. Keywords: I2C Bus, Microcontroller, Virtual Technology, Proteus.

Introduction

I2C serial bus is one of the bus standards that are widely used in the field of microelectronics communication control. It uses two transmission lines SDA and SCL to establish contact and transmission of information with microcontroller or peripheral devices. I2C serial bus is mainly used in microcontroller system expansion and multi-machine communication, with its simple and effectiveness advantages. [1] Different from traditional hardware simulation, we introduce the microcontroller virtual development techniques in the design of the I2C bus communication, use the Proteus software which is strong in simulation and analysis to simulate the microcontroller and its peripheral equipment, and design and modify the hardware and software for multiple I2C devices with computer. The success in the application of technology forms a bran-new system design concepts, its design process is as follows: schematic design and simulation - circuit modification and improvement - to draw the printed circuit board - hardware assembly and debugging. It breaks the traditional system design mode, and makes the system design flaws exposed early in the initial stage of design. The design process overcomes the deficiency in continuously modifying the design of the hardware model.

T. Zhang (Ed.): Instrumentation, Measurement, Circuits and Systems, AISC 127, pp. 355361. Springer-Verlag Berlin Heidelberg 2012 springerlink.com

356

F. Wu, L. Wu, and T. He

About Proteus Simulation Software

Proteus is a circuit analysis and physical simulation software, which is running on the Windows operating system, is put out by a British company named Labcenter. It can simulate and analyze all kinds of analog circuits and integrated circuits. With its large advantages such as the rich experiment resources, the short experimental period, less investment in hardware, small loss in the experiment, and the proximity of the actual design. [2] Proteus mainly includes the ISIS and the ARES. The main functions of ISIS are schematic design and simulation. And the ARES is mainly used in printed circuit board design. In addition to the features like other EDA tools, such as principles of layout, PCB automatic or manual routing, circuit simulation, the biggest feature of Proteus is the microcontroller-based design along with all the external circuit simulation. It can program on the virtual systems microcontroller directly, or use third-party application development and debugging environment in real-time virtual circuit debugging. In can predominate the operation of the program and the corresponding hardware circuit input and output states at any moment, when there is unconformity. It will track the Debug command in depth and find the problem and solution quickly. In addition, Proteus also has the function of interactive circuit simulation. It can display system input and output by using dynamic model of peripherals such as keyboard, LED / LCD, etc., or combining with the virtual instruments of Proteus such as oscilloscopes, logic analyzers, etc.

Design Principles of I2C Bus Communication

Hardware design At present there are many types of devices that can be hung on the I2C bus. We take the AT24C02 for example. While designing, SDA and SCL of the devices are added to the same name access to the bus terminal respectively, and then connected with the SDA, SCL pins of the master. Then all devices connected to the I2C bus are controlled devices, while the bus master is the one that can control the controlled devices, such as microcontrollers, PLC, etc. And I2C bus allows multiple masters. [3] The AT24C02 on the bus has a unique address 1010xxxyB, in which the high 4bit code is a constant while being made in factories, xxx is based on level of pins A2, A1, A0, and y is the R / W signal. When y equals to 1 is read, otherwise is writing. Table 1 is the A2, A1, A0 encoding table. It shows that there are eight AT24C02 can be linked to the I2C bus at most. When designing, we can connect the VSS, TEST to the ground, and change the A2, A1, A0 level status according to Table 1.

Communication Design for I2C Bus Based on Proteus Table 1. The AT24C02 address allocation table NO. U1 U2 U3 U4 U5 U6 U7 U8 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 A2 0 0 0 0 1 1 1 1 A1 0 0 1 1 0 0 1 1 A0 0 1 0 1 0 1 0 1 R/Y 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 R/W address 0A0H/0A1H 0A2H/0A3H 0A4H/0A5H 0A6H/0A7H 0A8H/0A9H 0AAH/0ABH 0ACH/0ADH 0AEH/0AFH

357

With comparison, we select AVR ATmega8 MCU as the master, which provides a fully compatible TWI I2C serial bus interface. Pins PC5/ADC5/SCL, PC4/ADC4/SDA are the clock signal and data signal of I2C bus respectively. Because they are open-drain pins, the circuit design requires an external pull-up resistor. The design block diagram is shown in Figure 1.
+5V
U1 A2 24C02 A1 U 2 A2 24C02 A1 A0 U 7 A2

+5V

U8 A2 24C02 A1 A0

+5V

M icrocontroller

10k 10k SDA SCL

A0

+5V

24C02 A1 A0

Fig. 1. Design schematics of hardware circuit

Software design On the I2C bus, the master recognizes the controller's address through the use of software addressing. It calculates each I2C devices read and writing address according to the actual hardware circuit diagram. For example Table 1 is an address table corresponding to the I2C devices shown in Figure 1. In the process of code execution, the master explains the instructions contained the address, and read data from or writes data to the corresponding I2C devices. [4] Figure 2 shows the timing diagram of I2C communication. The process can be discussed in three steps.

358

F. Wu, L. Wu, and T. He

START SCL 1 SDA 2 8

STOP ACK 9

Fig. 2. I2C bus data transfer sequence

(1) Start signal: sent by the master, that is SDA changes from high level to low level while SCL is high; (2)The address transmission or data transmission: First, address frame of I2C device sent by the master is made up of 7-bit address signal and a 1-bit reading-andwriting. When the read and write signal is 1 it is reading, otherwise is writing. The I2C device on the bus with the same address sent by the master is selected and returns a response signal to the master. Then, after receiving the response signal, the master starts to read data from or write data to the I2C device. The data transmission which is the same as the address transmission transfers in bytes and the length of each byte is 8. The first transmission is MSB while LSB the last is. The transmission of each byte is followed by a response signal, when the response signal is Ack, it means continuing to transmit data while Nack means the end of the case. (3) Stop signal: sent by the master, that is SDA changes from low level to high level while SCL is high; The system software is designed in modularization. Initialization program of the system, the read and write data program of I2C devices, and input or output device program that system may include are packaged as a separate function modules. All function modules are integrated to a complete system after each function module is successfully debugged, thereby reducing the difficulty of debugging the system while improving development efficiency. Source code of the program is written with a common build environment for AVR microcontroller ---- BASCOM-AVR, which contains a wealth of data types, a large number of simple and practical functions, and also develops some special peripheral functions, such as I2C statement, LCD statement, RC5 statements, etc. Now, we take AVR microcontroller communicating with I2C device U8 for example, to show I2C bus operation subroutine of read and writing. From Table 1, it is clear that the devices read address is & Haf and write address is & Hae. 1. Subroutine about microcontroller reads a data from I2C-bus I2CStart I2CWbyte &Haf I2CWbyte 0 I2CStart I2CWbyte &Haf I2CRbyte X , Nack I2CStop

Communication Design for I2C Bus Based on Proteus

359

2. Subroutine about microcontroller writes a data to I2C-bus I2CStart I2CWbyte &Hae I2CWbyte 0 I2CWbyte X I2CStop Waitms 20

Circuit Simulation and Results Analysis

In order to achieve the interactive simulation, the design also includes some input and output devices. We will use the 8 1 keyboard instead of command unit in microcontroller control process to achieve the read and write operations of the I2C device U1 ~ U8, and use the LM1602 LCD to export the simulation results. The introduction of the keyboard and LCD makes us finish a series of interactive experiments about the AT24C02 on the I2C bus. We take the data communication in a microcontroller control process for example. It requires pressing the button followed by K1 ~ K8 to write data 10 n + m (0 n 7,0 m 9) to the AT24C02 U1 ~ U8 respectively, then read out the 10 newly written data after an appropriate delay, and display the read results by LCD U10. Combine Figure 1 with the keyboard and display circuit, we use Proteus to design the simulation circuit which is shown in Figure 3.

Fig. 3. Simulation circuit of I2C bus communication

Create the design program files by running BASCOM-AVR software. On the one hand, set the Options-related attributes in the output column by selecting HEX file; on the other hand, put the source code in the file and save it as *. bas file, then compile the program and debug it, finally generate the *.hex file. [5] After checking the correctness of the simulation circuit in Figure 3, load the generated *.hex file on the microcontroller U9, and then run the Proteus I2C bus communication circuit in order to achieve a virtual simulation. Operate buttons K1 ~ K8 respectively, the corresponding output results is shown on the LCD screen as in Table 2. It is obvious that the results are fully matching to the design requirements. And so is strongly proved the design correctness and feasibility

360

F. Wu, L. Wu, and T. He

of the I2C bus communication by using Proteus. In addition, when pressing the button K8, the circuit simulation results are shown in Figure 4 screenshots.

Fig. 4. Proteus simulation results screenshot

Debugging Common Problems and Solutions

As the user is not thoroughly familiar with the I2C bus works, or doesnt operate properly to the Proteus simulation software or other reasons, there will be a range of hardware or software problems in the design process. We list some common points as follows, and solve them step by step according to the failure resulting from primary and secondary factors. 1) No response to the circuit simulation when operating all the keys Firstly, check whether the microcontroller U9 has been loaded the *.hex program file correctly. Secondly, operate buttons K1 ~ K8 successively and exam the level change of each key. The correct change should be high level - low level - high level, that is, it is the level stage of the low level only when the button is pressed, otherwise is high level. Thirdly, examine pins A2, A1, A0 of I2C devices U1 ~ U8 respectively, the correct level should be consistent with table 1. And at the same time, exam SDA and SCL level is whether the same with microcontrollers. Fourthly, check whether the LCD screen is working properly by loading a proper LCD display program to microcontroller U9. If it can correctly display, the LCD screen has no failure. Finally, check the designs program source code whether it is correct by using debug commands to single-step debug or debug trace. 2) No response to the circuit simulation when operating individual key Take no response to simulate circuit when operating the key K1 for example. It can, above all, rule out the failure possibilities of microcontroller U9 and LCD screen U10. Firstly, operate button K1 and examine its level change. The correct change should be high level - low level - high level, that is, it is the level stage of the low level only when the button is pressed, otherwise is high level. Secondly, examine pins

Communication Design for I2C Bus Based on Proteus

361

A2, A1, A0 of I2C devices U1 respectively, the correct level should be consistent with table 1. And at the same time, exam SDA and SCL level is whether the same with microcontrollers. 3) Error results in the circuit simulation after key operation Firstly, check whether the LCD screen is working properly by loading a proper LCD display program to microcontroller U9. If it can correctly display, show the LCD screen has no failure. Secondly, check the design of the program source code, and give emphasis to mainly examine the program of liquid crystal display and read and write operating of I2C device.

Conclusion

We describe the design of AVR microcontroller I2C bus communication module. It contains hardware design and realization of Proteus simulation circuit, uses BASCOM-AVR software to complete Software Programming, and has solved some common hardware and software problems. Simulation results show that the use of EDA tools Proteus for microcontroller virtual system design has many advantages, such as high efficiency, low cost, large proximity of the actual design, etc., and has great significance for microcontroller design and development. This method is particularly suitable for beginners to use SCM, and is also a powerful complement of SCM courses in teaching design experiment.

References
1. Chen, G.-J., Jia, J.-L.: Design of 12C bus system based on SCM. Chinese Journal of Scientific Instrument, 24652466, 2472 (June 2006) 2. Li, N., Liu, Y.-J.: Application of Proteus on Simulation for MCU. Modern Electronic Technique, 181182 (April 2007) 3. Zhang, L., Liao, J.-B., Kong, L.-W.: Simulation of SCM I2C bus communication with the digital potentiometer using Proteus. Electronic Measurement Technology, 4952 (November 2010) 4. Chen, Z.-H.: The realization of FC-Bus to MCS51 Single Chip Microcontroller family data gather system. Control & Automation, 6768 (January 2005) 5. Wu, F.-J., Xie, C.-Y., Huang, W.-K.: AVR Microcontroller virtual system design based on Proteus. Computer Knowledge and Technology, 10661067 (August 2008)