Design method and program of single chip microcomputer application system based on I2C serial bus

Publisher:Radiant777Latest update time:2018-03-24 Source: eefocusKeywords:I2C Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    At present, the diversified functions of consumer electronic products (such as color TVs, stereos, etc.) make the control circuit more complicated. The I2CBUS (Inter ICBUS) bus introduced by Philips is the most concise, effective and widely used bus format among many buses. The I2C bus is usually implemented in hardware, which requires the selected device to have an I2C bus interface, but the widely used MCS-51 series microcontrollers do not have a dedicated hardware part for the I2C bus. This article combines the author's use of the microcontroller 8031 ​​to control the stereo audio processing chip TDA7313 with an I2C bus interface, and introduces the design method and program of the I2C bus and the microcontroller application system based on the I2C serial bus.


    1 Introduction to I2C Bus

    1.1 Composition of I2C bus

    The I2C serial bus uses two signal lines, the bidirectional data line (SDA) and the serial clock line (SCL), to transmit information between devices connected to the bus. It is a multi-master bus, and Figure 1 shows its block diagram. Each device on the bus can be set with a unique address, and then send or receive information according to the set function. In addition to being a transmitter and receiver, the devices on the bus can also be set as masters and slaves when performing data transmission. The master controller usually starts data transmission on the bus and generates the clock signal required for data transmission. The other devices addressed by it are all slaves, which means that multiple devices with control buses can be connected to the bus.

Figure 1 I2C bus composition

    The data transmission rate on the I2C bus is 100 kbit/s, and can reach 400 kbit/s in fast mode. The number of devices connected to the bus is limited only by the bus capacitance of 400 pF. At the same time, in order to avoid confusion of bus signals, the output terminals of each device connected to the bus must be open collector or open drain to produce the "line and" function. The SDA and SCL lines on the I2C bus are both bidirectional transmission lines. They can be connected to the positive power supply terminal through a resistor. When the bus is in an idle state, both lines are high level.

    1.2 I2C bus data transmission format

    During the I2C bus transmission process, data transmission can only start when the bus is idle (both the SCL line and the SDA line are high), and any device on the bus can control the bus at this time. Figure 2 shows two specific start and stop conditions, where the start condition (S) is when the SCL line is high and the SDA line changes from high to low; and the end condition (P) is when the SCL line is high and the SDA line changes from low to high. During the data transmission process, when the SCL line is high, the SDA line must be stable high or low to make the data valid. The state of the SDA line can only change when the clock signal on the SCL line is low, and one clock pulse is required for each bit of data. All data is sent in bytes, and the number of bytes sent each time is unlimited. After each byte is sent, the master controller releases the SDA line (high level) and the slave pulls down the SDA line, so that the SDA line is stable low as a valid response bit to indicate successful transmission. At this time, the master controller must generate an additional clock pulse corresponding to this bit.

Figure 2 I2C serial bus data operation timing

Figure 3 shows the data transmission format of the I2C bus. The first part is the data transmission start signal, which is where data transmission begins; the second part is the slave address, which is used to select which slave to transmit data to; the third part is the read/write control bit, which is used to indicate the working mode of the slave, 0 means write, 1 means read; the fourth part is the confirmation signal sent back by the slave selected by the master to the master; the fifth part is the transmitted data, and each byte of data transmitted requires an acknowledgement bit; the sixth part is the end signal of data transmission.

Figure 3 Data transmission format

Figure 3 Data transmission format 

Each controlled device with an I2C bus interface has a unique fixed address. When the master controller sends data, the controlled device connected to the I2C bus will compare the 8-bit address information sent by the master controller after the start signal with its own address. If the two are the same, the controlled device is considered to be selected, and then receives or sends data according to the working mode specified by the read/write bit.

2 Implementation of I2C bus in microcontroller

The IC control chip used in this audio processing system is TDA7313, which is a stereo audio digital processing device with volume, left and right balance of high and low pitch, and front and back mixing adjustment. Its input channel can be selected, and it has corresponding external loudness adjustment function and I2C serial bus interface, so it can be widely used in car audio and high-fidelity systems. The connection between TDA7313 and microcontroller 8031 ​​and the basic pin definition are shown in Figure 4.

Figure 4 Interface circuit between MCU and TDA7313

Figure 4 Interface circuit between MCU and TDA7313 

Since the 8031 ​​microcontroller does not have an I2C bus hardware interface, the serial clock signal can only be generated by writing software. When the system transmits data, the microcontroller first gives a start signal; then sends the 7-bit address and read/write control bit of the device TDA7313 and waits for the response signal; after receiving the response signal, the system performs corresponding operations according to the access requirements. In the actual operation process, the CPU generally inputs a series of specific digital commands to TDA7313 to realize the audio processing of the entire system, so the operation of TDA7313 is mainly write operation.


Keywords:I2C Reference address:Design method and program of single chip microcomputer application system based on I2C serial bus

Previous article:Parallel expansion and interface design of I2C interface of 8051 microcontroller
Next article:Using the I/O port of a single-chip microcomputer to drive 74LS164

Recommended ReadingLatest update time:2024-11-15 07:05

PIC microcontroller application topic three: I2C reading and writing 24C02
Since I started learning microcontrollers, I have found I2C to be a very useful thing. It can greatly save our ports. Now I write the I2C program simulated by software, not only to share with you, but also to make a backup for myself. The following program uses I2C to store 24C02:    INCLUDE P16F5X.INC ; can also be u
[Microcontroller]
C8051F I2C (SMBus) Program
/******************************************************************************************************** * * File : ws_iic_port.h * Hardware Environment:  * Build Environment : Silicon LABs 3.42.00 / uVision3 V3.80 20100913 * Version :  * By : Su Wei Feng * *(c) Copyright 2005-2010, WaveShare *http://www.waveshare.ne
[Microcontroller]
Learning STM8 I2C
STM8's I2C interface 1. I2C mode selection interface has 4 modes: slave device transmission mode; slave device reception mode; master device transmission mode; master device reception mode. Under default conditions, the I2C module works in slave mode. The interface automatically switches from slave mode to master mod
[Microcontroller]
i2c bus AT24C02 memory read and write program
#include #define uint unsigned int //define unsigned int as uint #define uchar unsigned char //define unsigned char as uchar #define uchar unsigned char //define unsigned char as uchar #define uint unsigned int //define unsigned int as uint sbit sda=P3^3; //define I2C data line sbit scl=P3^2; //define I2C clock line
[Microcontroller]
How to use an oscilloscope to solve problems encountered in I2C communication development
The I2C bus is a two-wire serial bus introduced by PHLIPS in the 1980s. It was originally developed for audio and video equipment, and is now mostly used in various embedded systems to connect microcontrollers and their peripherals. The I2C bus only uses two communication lines (one is the serial data line "SDA" and
[Test Measurement]
How to use an oscilloscope to solve problems encountered in I2C communication development
Use P1 port to simulate I2C on 51
Below are the I2C basic level simulation functions and common functions implemented using ordinary C51.  /* Level simulation function and basic read and write function      void IIC_Start(void);      void IIC_Stop(void);      void SEND_0(void);      void SEND_1(void);      bit Check_Acknowledge(void);      void Write
[Microcontroller]
I2C Bus Driver
#include "linux/kernel.h" #include "linux/module.h" #include "linux/i2c.h" #include "linux/init.h" #include "linux/time.h" #include "linux/interrupt.h" #include "linux/delay.h" #include "linux/errno.h" #include "linux/err.h" #include "linux/platform_device.h" #include "linux/pm_runtime.h" #include
[Microcontroller]
I2C Bus Driver
High Efficiency I2C USB Power Manager and Li-Ion Battery Charger with Digital Control and Status Readback
        Linear Technology Corporation introduces the LTC4099, an autonomous I2C controlled, high efficiency power manager, ideal diode controller and Li-Ion/Polymer battery charger for USB powered portable devices such as media players, digital cameras, PDAs, PNDs and smart phones. Parameters including input current li
[Power Management]
High Efficiency I2C USB Power Manager and Li-Ion Battery Charger with Digital Control and Status Readback
Latest Microcontroller Articles
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号