PIC microcontroller port expansion technology based on I2C bus

Publisher:科技飞翔Latest update time:2012-01-30 Source: 微计算机信息 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Overview

With the development of single-chip microcomputer technology, single-chip microcomputers are increasingly used in the field of electromechanical products. On the one hand, it is hoped that the embedded system composed of single-chip microcomputers is as powerful as possible, with strong processing capabilities and many control objects; on the other hand, it is hoped that the cost of the entire system is as low as possible, that is, it has a good cost performance. Therefore, in practical applications, it is often encountered that the I/0 interface resources of the single-chip microcomputer are insufficient. In some more complex application systems, due to the large number of controlled objects, such as controlling the display of multiple LED digital tubes and the display of more than 30 status channels, the contradiction between port supply and demand is particularly prominent. The usual solution is to use external I/0 interfaces such as 8155, 8255, 8259, 74HC164, 74HC165, 74LS373 and 74LS245, which will inevitably make the system more complex, increase costs and reduce reliability.

At present, most of the powerful single-chip microcomputers use FLASH technology, and add advanced and practical functions such as SPI, I2C, CAN, etc. on the basis of the traditional USART serial communication function; and many peripheral chips have communication interfaces such as I2C, such as the ZLG7290 chip with 64 buttons and 8×8 LED digital tube drivers. Therefore, the single-chip microcomputer port expansion can choose a more convenient and more powerful expansion method.

The I2C (Inter-IC, IC TO IC) bus was developed by Philips Semiconductors in the mid-1980s and was originally used for audio and video purposes. After I2C was expanded to the system management bus SMBus, it can be used for power management and communication between the CPU and other components. I2C supports multi-master mode. The transmission rate specified in version 2.1 is up to 100kbit/s in standard mode, 400kbit/s in fast mode, and 3.4Mbit/s in high-speed mode[1]. Since only two port pins of the microcontroller are needed to transmit data of arbitrary characteristics, the I2C bus protocol has been widely used and has promoted the development of a large number of I2C external chips. The I2C bus can be used to control IC cards, data conversion[2], LCD control, clock control[3], memory control[4], multi-machine communication[5], etc. This article mainly discusses the control problem of the ZLG7290 chip based on the I2C interface when MICROCHIP's PIC18F458 is used to control the car body status display.

2. I2C bus working sequence

The serial bus I2C consists of a data line SDA and a clock line SCL. The device connected to the I2C bus can be a master (responsible for generating the clock SCL signal) or a slave device Slave, which can be used as a transmitter or a receiver. The I2C bus is converted into 9 bits at a time. The first 8 bits transmit data in the order from MSB to LSB. The 9th bit is the ACK bit. When the SCL signal is high, the change of the SDA state is used to start and stop the conversion. In addition, the transmission of each data bit requires the support of an SCL cycle. During the data transmission process, when SCL is high, the data on the SDA line must be maintained. Only when SCL is low can the state (data) of the SDA line be changed. The basic I2C communication process is: START (RESTART) à 7-bit peripheral chip address + R/~W control bit à 8-bit peripheral chip internal register address à multiple data bytes transmitted à STOP. The I2C bus data transmission timing is shown in Figure 1.


Figure 1 I2C bus data transmission timing

3. ZLG7290 expansion chip

ZLG7290 is a keyboard and LED driver based on I2C interface developed by Guangzhou Zhou Ligong Single Chip Microcomputer Development Co., Ltd. It can drive 8-bit common cathode digital tube or 64 independent LEDs and 64 buttons. ZLG7290 provides two control modes: register image control and command interpretation control. Register image control refers to directly accessing the underlying registers in byte operation mode to achieve basic control functions; command interpretation control refers to indirectly accessing the underlying registers by interpreting the instructions in the command buffer CmdBuf0/CmdBuf1 to achieve extended control functions such as register bit operations, circular shift of display buffer, and operand decoding. The slave address of ZLG7290 is 70H (01110000B), and the address of the internal register is 00~17H. The internal function block diagram of ZLG7290 is shown in Figure 2. In this application, the register image control mode is adopted to control the LED.

Figure 2 ZLG7290 internal function block diagram

4. Implementation of PIC18F458 based on I2C communication

PIC18F458 is a high-end 8-bit FLASH microcontroller with an integrated CAN controller developed by MICROCHIP. It has 32K bytes of FLASH program RAM space, 1536 bytes of RAM + 256 bytes of EEPROM for data storage, and a total of 33 I/O ports[6][7]. The master synchronous serial port (MSSP) module of PIC18F458 provides SPI and I2C communication functions. Pins RC4 and RC3 are used as the data SDA line and clock SCL line in I2C mode respectively. There are 6 registers related to I2C communication control inside, namely: MSSP control register 1 (SSPCON1), MSSP control register 2 (SSPCON2), MSSP status register (SSPSTAT), serial receive/transmit buffer (SSPBUF), MSSP shift register (SSPSR) and MSSP address register (SSPADD). Among them, SSPCON1/SSPCON2 are used to set the working mode, and SSPADD is used to set the device address (when PIC18F458 is used as SLAVE) or communication baud rate (when PIC18F458 is used as MASTER). In MASTER mode, the value of SSPADD should satisfy the following formula:

(Dark/4)/FI2C=SSPADD+1

in:

Fosc/4: PIC18F458 internal clock frequency, fixed to 1/4 of the crystal frequency;

FI2C: The maximum rate of I2C communication, unit: kbit/s, generally 100kbit/s

The SSPADD value must be rounded to the smallest integer greater than or equal to the calculated value.

Figure 3 shows the hardware wiring when PIC18F458 controls ZLG7290 as the vehicle body status display driver. Pins 19 and 20 of ZLG7290 are used to realize communication control with PIC18F458. The display control is realized in the program mainly by calling functions WriteByte(SCANNUM, 0x01) and WriteByte(DPRAMi, Dig2word), where SCANNUM is the number of scans and DPRAMi (i=0~7) is the segment code display buffer corresponding to the 8 digital tubes. As shown in Figure 3, if all 8 LEDs in the column where LED D1 is located are to be lit, the corresponding display buffer value should be 0XFF.

Figure 3 Hardware wiring when PIC18F458 controls ZLG7290 as a vehicle body status display driver

5. Conclusion

Using the I2C bus interface to expand the port of the microcontroller greatly simplifies the design of the peripheral hardware circuit of the embedded system and improves the reliability of the system; at the same time, it also simplifies the design of the system control software and achieves good application results in the vehicle body condition display control system based on PIC18F458. According to the method introduced in this article, ZLG7290 or similar chips can be easily applied to other types of MCU applications of MICROCHIP.

References

1.THE I2C-BUS SPECIFICATION,VERSION 2.1,www.semiconductors.philips.com /i2c/support

2. Wu Qiang, Huang Shihong. Research on the application of I2C bus in intelligent vibration tester. Microcomputer Information, 2002(10)

3. Li Cai et al. Application of clock chip PCF8563 in ocean optical buoy. Electronic Products World, 2003(7)

4. Jin Ming, Tao Weiqing. MSP430 series microcontroller and I2C bus EEPROM interface. Instrument and Meter User, 2003 (6)

5. Li Qiusheng, Wang Yuezhong. Application of VB6-based PC and multiple single-chip microcomputer communication in lithium battery detection and formation equipment. Microcomputer Information, 2003 (10)

6.PIC18FXX8 DATA SHEET, www.microchip.com

7.[美]约翰 B.皮特曼 著,郑红等译. PIC18F452微控制器嵌入式设计.科学出版社,2005,1

Reference address:PIC microcontroller port expansion technology based on I2C bus

Previous article:Design of Embedded Remote Controller Based on Telephone Network
Next article:Design Research of PIC18F452

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号