[go: up one dir, main page]

CN1292360C - A device and method for realizing automatic reading and writing of internal integrated circuit equipment - Google Patents

A device and method for realizing automatic reading and writing of internal integrated circuit equipment Download PDF

Info

Publication number
CN1292360C
CN1292360C CN 200410000775 CN200410000775A CN1292360C CN 1292360 C CN1292360 C CN 1292360C CN 200410000775 CN200410000775 CN 200410000775 CN 200410000775 A CN200410000775 A CN 200410000775A CN 1292360 C CN1292360 C CN 1292360C
Authority
CN
China
Prior art keywords
register
read
generation module
data
command generation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN 200410000775
Other languages
Chinese (zh)
Other versions
CN1558332A (en
Inventor
周广水
何宁
郑斌儒
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZTE Corp
Original Assignee
ZTE Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by ZTE Corp filed Critical ZTE Corp
Priority to CN 200410000775 priority Critical patent/CN1292360C/en
Publication of CN1558332A publication Critical patent/CN1558332A/en
Application granted granted Critical
Publication of CN1292360C publication Critical patent/CN1292360C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Landscapes

  • Information Transfer Systems (AREA)

Abstract

本发明公开一种实现自动读写I2C设备的装置和方法,装置由硬件实现的指令产生模块和读写操作执行模块组成,指令产生模块通过异步访问总线分别与主动设备及读写操作执行模块相连,读写操作执行模块通过I2C总线与I2C设备相连,读写时,主动设备提供启动信号、读/写信号以及I2C设备的设备地址、寄存器地址和要写入寄存器的数据,指令产生模块自动产生访问I2C设备所需的指令,依序送到读写操作执行模块,读写操作执行模块再遵照I2C总线协议产生访问I2C设备需要的信号时序,执行对I2C设备的读写操作,本发明装置还向主动设备返回指令执行情况。本发明可以简化访问I2C设备时的软件操作,节省CPU时间。

The invention discloses a device and method for realizing automatic reading and writing of I2C equipment. The device is composed of an instruction generation module realized by hardware and a read and write operation execution module. The instruction generation module is respectively connected with the active device and the read and write operation execution module through an asynchronous access bus. , the read and write operation execution module is connected to the I2C device through the I2C bus. When reading and writing, the active device provides the start signal, the read/write signal, the device address of the I2C device, the register address and the data to be written into the register, and the command generation module automatically generates The instructions required to access the I2C device are sent to the read and write operation execution module in sequence, and the read and write operation execution module generates the signal timing required to access the I2C device according to the I2C bus protocol, and executes the read and write operations on the I2C device. The device of the present invention also Return command execution status to active device. The invention can simplify the software operation when accessing the I2C device and save CPU time.

Description

一种实现自动读写内部集成电路设备的装置和方法A device and method for realizing automatic reading and writing of internal integrated circuit equipment

技术领域technical field

本发明涉及一种集成电路设备的读写装置和方法,尤其涉及数据通讯领域中实现对I2C(inter-integrated circuit内部集成电路,一种标准接口电路,是由PHILIPS公司提出发明的)设备自动读或写的装置和方法。The present invention relates to a device and method for reading and writing integrated circuit equipment, in particular to realizing automatic reading of I2C (inter-integrated circuit internal integrated circuit, a standard interface circuit, invented by PHILIPS) equipment in the field of data communication. or written apparatus and methods.

背景技术Background technique

在很多的情况下电子设备系统或CPU应用系统具有低速异步访问总线接口,但没有I2C总线(包括SDA和SCL两个信号线,分别表示是I2C总线的数据信号线和时钟信号线,以下的I2C总线均是指这两个信号线)接口,而此时需要对I2C设备进行读、写访问。这就需要进行低速异步访问总线和I2C接口总线的转换。In many cases, the electronic equipment system or CPU application system has a low-speed asynchronous access bus interface, but there is no I2C bus (including two signal lines of SDA and SCL, which respectively represent the data signal line and clock signal line of the I2C bus. The following I2C The bus refers to the two signal lines) interface, and at this time, the I2C device needs to be read and written. This requires conversion of the low-speed asynchronous access bus and the I2C interface bus.

现有的实现低速异步访问总线和I2C接口总线转换的方法一般比较复杂,在WWW.FPGA.COM.CN网站上,XILINX(美国FPGA芯片生产厂商)提供的一个最新的I2C总线控制IP CORE(集成电路逻辑内核),就是采用这种较复杂的方法,若主动设备(比如CPU)要访问一个I2C设备,要CPU一步一步按I2C总线协议执行。Existing methods for realizing low-speed asynchronous access bus and I2C interface bus conversion are generally more complicated. On the WWW.FPGA.COM.CN website, a newest I2C bus control IP CORE (integrated circuit logic core), is to adopt this more complex method, if the active device (such as CPU) wants to access an I2C device, the CPU is required to execute step by step according to the I2C bus protocol.

例如,CPU要执行读一个I2C设备,要执行的步骤是:For example, if the CPU wants to read an I2C device, the steps to be performed are:

1)CPU把I2C的设备地址(DEVICE ADDRESS)写到数据寄存器,并设置写标志;1) The CPU writes the I2C device address (DEVICE ADDRESS) to the data register, and sets the write flag;

2)CPU读状态寄存器,判断I2C总线是否忙,若不忙执行下一步;2) The CPU reads the status register to determine whether the I2C bus is busy, and if not, execute the next step;

3)CPU写控制寄存器,发送“开始”(START)和发送I2C设备地址(DEVICE ADDRESS);3) The CPU writes the control register, sends "START" and sends the I2C device address (DEVICE ADDRESS);

4)CPU读状态寄存器,判断发送是否完毕并且收到从设备的回应(ACK),若收到回应,则进行下一步操作;4) The CPU reads the status register to determine whether the transmission is complete and receives a response (ACK) from the slave device. If a response is received, proceed to the next step;

5)CPU把要访问I2C设备的寄存器地址(WORD ADDRESS)写到数据寄存器;5) The CPU writes the register address (WORD ADDRESS) to be accessed to the I2C device to the data register;

6)CPU写控制寄存器,把I2C设备的寄存器地址送出;6) The CPU writes the control register and sends out the register address of the I2C device;

7)CPU读状态寄存器,判断发送是否完毕并且收到从设备的回应(ACK)。若收到回应,则进行下一步操作;7) The CPU reads the status register, judges whether the sending is completed and receives a response (ACK) from the slave device. If a response is received, proceed to the next step;

8)CPU写控制寄存器,发送“结束”(STOP);8) The CPU writes the control register and sends "end" (STOP);

9)CPU延时(因有些I2C设备需要附加延时,比如AT24C04要求上一个“结束”和下一个“开始”之间必须有10毫秒的延时);9) CPU delay (because some I2C devices require additional delay, such as AT24C04 requires a 10 millisecond delay between the last "end" and the next "start");

10)CPU把I2C的设备地址(DEVICE ADDRESS)写到数据寄存器,并设置读标志;10) The CPU writes the I2C device address (DEVICE ADDRESS) to the data register, and sets the read flag;

11)CPU写控制寄存器,发送“开始”(START)和发送I2C设备地址(DEVICE ADDRESS);11) The CPU writes the control register, sends "START" and sends the I2C device address (DEVICE ADDRESS);

12)CPU读状态寄存器,判断发送是否完毕并且收到从设备的回应(ACK),若收到回应,则进行下一步操作;12) The CPU reads the status register to determine whether the transmission is complete and receives a response (ACK) from the slave device. If a response is received, proceed to the next step;

13)CPU设置控制寄存器,使逻辑处于接收状态;13) The CPU sets the control register so that the logic is in the receiving state;

14)判断状态寄存器,数据是否接收完成。完成则执行下一步14) Judging the status register, whether the data reception is completed. When done, go to the next step

15)CPU读数据寄存器,得到要读的数据。15) The CPU reads the data register to obtain the data to be read.

可以看出,每一步都离不开CPU的操作和判断,不但程序复杂,而且CPU大量的时间花在等待慢速设备的响应上。It can be seen that each step is inseparable from the operation and judgment of the CPU. Not only is the program complicated, but the CPU spends a lot of time waiting for the response of the slow device.

由于I2C设备是较慢速的设备,访问这样的慢速设备较耗CPU的时间;若用软件一步一步操作,包括发送START信号,发送数据,检测SLAVE设备(从设备)的响应信号,再送STOP信号。每一步操作都要求外部处理器参与发送指令或判断等,将会浪费CPU的大量操作周期,对于CPU处理性能要求较高的系统来说,这是非常不划算的,也是不可取的。另外,若用软件实现指导操作访问I2C设备,要求使用者非常了解I2C总线协议,必须按I2C总线的协议一步步完成操作,包括延时多长等都要精确计算。Since the I2C device is a relatively slow device, accessing such a slow device consumes more CPU time; if you use software to operate step by step, including sending START signal, sending data, detecting the response signal of the SLAVE device (slave device), and then sending STOP Signal. Every step of operation requires an external processor to participate in sending instructions or judgments, etc., which will waste a large number of operating cycles of the CPU. For systems with high CPU processing performance requirements, this is very uneconomical and undesirable. In addition, if the software is used to guide the operation and access the I2C device, the user is required to understand the I2C bus protocol very well, and must complete the operation step by step according to the I2C bus protocol, including the accurate calculation of the delay time.

发明内容Contents of the invention

本发明要解决的技术问题是克服现有技术存在的访问内部集成电路设备时操作繁琐,浪费CPU时间的缺陷,提供一种实现自动读写内部集成电路备的装置及方法。The technical problem to be solved by the present invention is to overcome the defects of cumbersome operation and waste of CPU time in the prior art when accessing internal integrated circuit equipment, and provide a device and method for automatically reading and writing internal integrated circuit equipment.

本发明的实现自动读写内部集成电路设备的装置,包括用硬件实现的指令产生模块和读写操作执行模块,所述指令产生模块通过异步访问总线分别与主动设备及所述读写操作执行模块相连,所述读写操作执行模块通过内部集成电路总线与内部集成电路设备相连,其中:The device for automatically reading and writing internal integrated circuit devices of the present invention includes an instruction generation module and a read-write operation execution module realized by hardware, and the instruction generation module communicates with the active device and the read-write operation execution module respectively through an asynchronous access bus connected, the read and write operation execution module is connected to the internal integrated circuit device through the internal integrated circuit bus, wherein:

所述指令产生模块,用于接收所述主动设备提供的启动信号、读/写信号以及内部集成电路设备的设备地址、寄存器地址和要写入寄存器的数据,自动产生访问内部集成电路设备所需的指令,依序送到所述读写操作执行模块,并向所述主动设备返回指令执行情况和从内部集成电路设备读出的数据;The instruction generation module is used to receive the start signal provided by the active device, the read/write signal, the device address of the internal integrated circuit device, the register address and the data to be written into the register, and automatically generate the required instruction for accessing the internal integrated circuit device. The instructions are sent to the read and write operation execution module in sequence, and the execution status of the instructions and the data read from the internal integrated circuit device are returned to the active device;

所述读写操作执行模块,用于根据所述指令产生模块的指令,遵照内部集成电路总线协议产生访问内部集成电路设备需要的信号时序,执行对内部集成电路设备的读写操作,并向所述指令产生模块返回指令执行情况。The read and write operation execution module is used to generate the signal timing required to access the internal integrated circuit device according to the instructions of the instruction generation module according to the internal integrated circuit bus protocol, execute the read and write operations on the internal integrated circuit device, and send to all The instruction generation module returns the execution status of the instruction.

上述装置可具有以下特点:所述指令产生模块在检测到主动设备要写一个内部集成电路设备时,依次发送开始指令、设备地址指令及写指示、寄存器地址指令、数据指令和停止指令。The above-mentioned device may have the following characteristics: when the instruction generation module detects that the active device is about to write an internal integrated circuit device, it sequentially sends a start instruction, a device address instruction and a write instruction, a register address instruction, a data instruction, and a stop instruction.

上述装置可具有以下特点:所述指令产生模块在检测到主动设备要读一个内部集成电路设备时,依次发送开始指令、设备地址指令及写指示、寄存器地址指令、停止指令、开始指令、设备地址指令及读指示、接收数据指令和停止指令。The above-mentioned device may have the following characteristics: when the instruction generation module detects that the active device wants to read an internal integrated circuit device, it sequentially sends a start instruction, a device address instruction and a write instruction, a register address instruction, a stop instruction, a start instruction, and a device address Command and read instructions, receive data instructions and stop instructions.

上述装置可具有以下特点:所述指令产生模块进一步包含:The above-mentioned device may have the following characteristics: the instruction generation module further includes:

命令控制寄存器,由所述主动设备的启动信号和读/写信号设置相应控制位的值,发动对内部集成电路设备读或写,并在执行失败时设置错误标志;Command control register, the value of the corresponding control bit is set by the start signal and the read/write signal of the active device, and the internal integrated circuit device is read or written, and an error flag is set when the execution fails;

设备地址寄存器,用于存储要访问的内部集成电路设备的设备地址;A device address register for storing the device address of the internal integrated circuit device to be accessed;

寄存器地址寄存器,用于存储要访问的内部集成电路设备的寄存器的地址;A register address register for storing the address of the register of the internal integrated circuit device to be accessed;

写入数据寄存器,用于存储要写的数据;Write to the data register, used to store the data to be written;

读出数据寄存器,用于存储要读出的数据;read data register, used to store the data to be read;

分频设置寄存器,用于设置送出的SDA/SCL信号的频率与输入的CLK频率之间的倍数关系;The frequency division setting register is used to set the multiple relationship between the frequency of the SDA/SCL signal sent and the frequency of the input CLK;

所述主动设备通过异步总线的地址信号对上述寄存器进行选择。The master device selects the above-mentioned registers through the address signal of the asynchronous bus.

上述装置可具有以下特点:所述指令产生模块向所述主动设备返回指令执行情况是通过在一次读或写操作完成后设置一个中断信号,或者在命令控制寄存器执行完操作后将相应的比特位自动清零,或者通过以上两种方式的结合来实现的。The above-mentioned device may have the following characteristics: the command generation module returns the execution status of the command to the active device by setting an interrupt signal after a read or write operation is completed, or setting the corresponding bit Automatic clearing, or a combination of the above two methods.

上述装置可具有以下特点:所述读写操作执行模块包含命令寄存器、接收数据寄存器、发送数据寄存器、时钟产生单元、START产生单元、STOP产生单元、数据发送单元和数据接收单元,其中:The above-mentioned device may have the following characteristics: the read-write operation execution module includes a command register, a receiving data register, a sending data register, a clock generating unit, a START generating unit, a STOP generating unit, a data sending unit and a data receiving unit, wherein:

所述命令寄存器,由所述指令产生模块的指令设置相应控制位的值,控制所述START产生单元、STOP产生单元、数据发送单元和数据接收单元的启动,并在操作执行完成后将相应位清零;The command register, the value of the corresponding control bit is set by the instruction of the instruction generation module, controls the startup of the START generation unit, the STOP generation unit, the data sending unit and the data receiving unit, and sets the corresponding bit after the operation is completed. Clear;

所述接收数据寄存器,用于缓存数据接收单元接收到的数据;The receiving data register is used for buffering the data received by the data receiving unit;

所述发送数据寄存器,用于缓存数据发送单元将要发送的数据;The sending data register is used for buffering the data to be sent by the data sending unit;

时钟产生单元,用于产生读写操作执行模块中各模块所需的时钟;A clock generating unit is used to generate clocks required by each module in the read and write operation execution module;

所述START产生单元,用于产生内部集成电路总线协议中规定的START时序;The START generating unit is used to generate the START timing specified in the inter-integrated circuit bus protocol;

所述STOP产生单元,用于产生内部集成电路总线协议中规定的STOP时序;The STOP generating unit is used to generate the STOP timing specified in the internal integrated circuit bus protocol;

所述数据发送单元,用于依照内部集成电路总线协议规定的SDA、SCL的时序,将所述发送数据寄存器中的数据发送到内部集成电路总线上;The data sending unit is used to send the data in the sending data register to the internal integrated circuit bus according to the timing of SDA and SCL stipulated in the internal integrated circuit bus protocol;

所述数据接收单元,用于依照内部集成电路总线协议规定的SDA、SCL的时序,接收内部集成电路总线上的数据。The data receiving unit is used for receiving data on the internal integrated circuit bus according to the timing of SDA and SCL stipulated in the internal integrated circuit bus protocol.

上述装置可具有以下特点:所述指令产生模块和读写操作执行模块之间的异步总线包括复位信号、时钟信号、写使能信号、发送数据寄存器选择信号、命令寄存器选择信号、数据总线输入和输出信号,以及错误指示信号的线路,所述错误指示信号由所述命令寄存器的控制位产生,用于向所述指令产生模块返回指令执行情况。The above-mentioned device may have the following characteristics: the asynchronous bus between the instruction generation module and the read and write operation execution module includes a reset signal, a clock signal, a write enable signal, a sending data register selection signal, a command register selection signal, a data bus input and An output signal, and a circuit of an error indication signal, the error indication signal is generated by the control bit of the command register, and is used to return the instruction execution status to the instruction generation module.

本发明的实现自动写内部集成电路设备的方法,应用于主动设备通过硬件实现的指令产生模块和写操作执行模块与内部集成电路总线相连的系统中,该方法包括以下步骤:The method for realizing automatic writing of the internal integrated circuit device of the present invention is applied to a system in which the instruction generation module and the write operation execution module realized by the active device through hardware are connected to the internal integrated circuit bus, and the method includes the following steps:

(a)所述主动设备将要访问的内部集成电路设备的地址,写入所述指令产生模块的设备地址寄存器;(a) The address of the internal integrated circuit device to be accessed by the active device is written into the device address register of the instruction generation module;

(b)所述主动设备将要访问的内部集成电路设备寄存器的地址写入所述指令产生模块的寄存器地址寄存器;(b) the active device writes the address of the internal integrated circuit device register to be accessed into the register address register of the instruction generating module;

(c)所述主动设备将要写入的数据写入所述指令产生模块的写入数据寄存器;(c) the active device writes the data to be written into the write data register of the instruction generating module;

(d)所述主动设备设置所述指令产生模块中命令控制寄存器的相应BIT位启动写操作;(d) the active device sets the corresponding BIT bit of the command control register in the instruction generation module to start the write operation;

(e)所述指令产生模块自动产生写内部集成电路设备所需的指令,依序送到所述写操作执行模块;(e) The instruction generation module automatically generates the instructions needed to write the internal integrated circuit device, and sends them to the write operation execution module in sequence;

(f)所述写操作执行模块根据所述指令产生模块的指令,遵照内部集成电路总线协议产生写内部集成电路设备的信号时序并完成写操作,返回指令执行情况;(f) The write operation execution module generates the signal sequence for writing the internal integrated circuit device according to the instruction of the instruction generation module according to the internal integrated circuit bus protocol and completes the write operation, and returns the execution status of the instruction;

(g)所述指令产生模块向所述主动设备返回指令执行情况;(g) the command generation module returns the execution status of the command to the active device;

(h)所述主动设备判断操作正确完成后,结束一次写操作。(h) After the active device judges that the operation is completed correctly, it ends a write operation.

上述方法中,所述步骤(h)后,如果下一次操作与上一次操作访问的是同一内部集成电路设备,则直接返回步骤(b),否则返回步骤(a)。In the above method, after step (h), if the next operation accesses the same internal integrated circuit device as the previous operation, then directly return to step (b), otherwise return to step (a).

上述方法中,所述步骤(e)中,所述指令产生模块依次发送开始指令、设备地址指令及写指示、寄存器地址指令、数据指令和停止指令。In the above method, in the step (e), the instruction generating module sequentially sends a start instruction, a device address instruction and a write instruction, a register address instruction, a data instruction and a stop instruction.

上述方法中,所述步骤(h)中,所述主动设备通过所述指令产生模块的中断报出,或者检测所述指令产生模块相应控制位的值来确认操作是否正确完成;通过检测所述指令产生模块的错误指示位的值来判断是否要进行错误处理操作。In the above method, in the step (h), the active device reports through the interrupt of the instruction generation module, or detects the value of the corresponding control bit of the instruction generation module to confirm whether the operation is completed correctly; by detecting the The command generates the value of the error indication bit of the module to determine whether to perform error handling operations.

本发明的自动读内部集成电路设备的方法,应用于主动设备通过硬件实现的指令产生模块和读操作执行模块与内部集成电路总线相连的系统中,该方法包括以下步骤:The method for automatically reading an internal integrated circuit device of the present invention is applied to a system in which an active device realizes an instruction generation module and a read operation execution module connected to the internal integrated circuit bus through hardware, and the method includes the following steps:

(a)所述主动设备将要访问的内部集成电路设备的地址,写入所述指令产生模块的设备地址寄存器;(a) The address of the internal integrated circuit device to be accessed by the active device is written into the device address register of the instruction generation module;

(b)所述主动设备将要访问的内部集成电路设备寄存器的地址写入所述指令产生模块的寄存器地址寄存器;(b) the active device writes the address of the internal integrated circuit device register to be accessed into the register address register of the instruction generating module;

(c)所述主动设备设置所述指令产生模块中命令控制寄存器的相应BIT位启动读操作;(c) the active device sets the corresponding BIT bit of the command control register in the instruction generation module to start a read operation;

(d)所述指令产生模块自动产生读内部集成电路设备所需的指令,依序送到所述读操作执行模块;(d) The instruction generation module automatically generates the instructions needed to read the internal integrated circuit device, and sends them to the read operation execution module in sequence;

(e)所述读操作执行模块根据所述指令产生模块的指令,遵照内部集成电路总线协议产生读内部集成电路设备的信号时序并完成读操作,并返回指令执行情况;(e) The read operation execution module generates the signal sequence for reading the internal integrated circuit device according to the instruction of the instruction generation module according to the internal integrated circuit bus protocol and completes the read operation, and returns the execution status of the instruction;

(f)所述指令产生模块向所述主动设备返回读出的数据以及指令执行情况;(f) The instruction generating module returns the read data and instruction execution status to the active device;

(g)所述主动设备判断操作正确完成后,从所述指令产生模块读出数据,结束一次读操作。(g) After the active device judges that the operation is completed correctly, it reads data from the instruction generation module and ends a read operation.

上述方法中,所述步骤(g)后,如果下一次操作与上一次操作访问的是同一内部集成电路设备,则直接返回步骤(b),否则返回步骤(a)。In the above method, after step (g), if the next operation accesses the same internal integrated circuit device as the previous operation, then directly return to step (b), otherwise return to step (a).

上述方法中,所述步骤(d)中,所述指令产生模块依次发送开始指令、设备地址指令及写指示、寄存器地址指令、停止指令、开始指令、设备地址指令及读指示、接收数据指令和停止指令。In the above method, in the step (d), the instruction generating module sequentially sends a start instruction, a device address instruction and a write instruction, a register address instruction, a stop instruction, a start instruction, a device address instruction and a read instruction, a receive data instruction, and stop command.

上述方法中,所述步骤(g)中,所述主动设备通过所述指令产生模块的中断报出,或者检测所述指令产生模块相应控制位的值来确认操作是否正确完成;通过检测所述指令产生模块的错误指示位的值来判断是否要进行错误处理操作。In the above method, in the step (g), the active device reports through the interrupt of the instruction generation module, or detects the value of the corresponding control bit of the instruction generation module to confirm whether the operation is completed correctly; by detecting the The command generates the value of the error indication bit of the module to determine whether to perform error handling operations.

由上可知,本发明由硬件实现的指令产生模块产生访问内部集成电路设备需要的一些指令,来取代软件的一些工作,从而完成简化软件繁琐的操作;由读写操作执行模块根据指令产生模块的指令,并遵照内部集成电路总线协议,完成访问内部集成电路设备的具体操作,从而由本发明的装置自动兼容内部集成电路总线协议。从而改变了访问内部集成电路设备过分依赖CPU的这种现象,腾出CPU更多的时间去做其它更重要的工作。同时,让使用者不需要了解繁琐的内部集成电路总线协议,简化了软件的工作量。As can be seen from the above, the instruction generation module implemented by hardware in the present invention generates some instructions needed to access the internal integrated circuit device to replace some work of the software, thereby completing the tedious operation of simplified software; instructions, and follow the internal integrated circuit bus protocol to complete the specific operation of accessing the internal integrated circuit device, so that the device of the present invention is automatically compatible with the internal integrated circuit bus protocol. Thereby changing the phenomenon that the access to the internal integrated circuit device relies too much on the CPU, freeing up more time for the CPU to do other more important work. At the same time, the user does not need to understand the cumbersome internal integrated circuit bus protocol, which simplifies the workload of the software.

附图说明Description of drawings

图1是本发明实施例自动读写I2C设备的装置的结构框图;Fig. 1 is the structural block diagram of the device of automatic reading and writing I2C equipment of the embodiment of the present invention;

图2和图3分别是本发明实施例主动设备和指令产生模块之间的异步访问总线写时序和读时序图;Fig. 2 and Fig. 3 are respectively the asynchronous access bus write timing diagram and read timing diagram between the active device and the instruction generation module of the embodiment of the present invention;

图4A和图4B是本发明实施例主动设备访问本发明装置的流程图;FIG. 4A and FIG. 4B are flow charts of an active device accessing the apparatus of the present invention according to an embodiment of the present invention;

图5是本发明实施例指令产生模块的产生指令的流程图;Fig. 5 is the flow chart of the generation instruction of the instruction generation module of the embodiment of the present invention;

图6是本发明实施例指令产生模块写时序的示意图;Fig. 6 is a schematic diagram of the write sequence of the instruction generation module of the embodiment of the present invention;

图7是本发明实施例指令产生模块读时序的示意图;Fig. 7 is a schematic diagram of the read sequence of the instruction generation module according to the embodiment of the present invention;

图8是I2C总线的传输时序图。Fig. 8 is a transmission timing diagram of the I2C bus.

具体实施方式Detailed ways

本发明实施例自动读写I2C设备的装置如图1所示,该装置由指令产生模块1和读写操作执行模块2组成,采用FPGA或CPLD来实现。指令产生模块1通过异步访问总线分别与主动设备4和读写操作执行模块2相连,读写操作执行模块2通过I2C总线与I2C设备3相连。其中:The device for automatically reading and writing I2C devices in the embodiment of the present invention is shown in Figure 1. The device is composed of a command generation module 1 and a read and write operation execution module 2, and is implemented by FPGA or CPLD. The command generation module 1 is connected to the active device 4 and the read and write operation execution module 2 respectively through the asynchronous access bus, and the read and write operation execution module 2 is connected to the I2C device 3 through the I2C bus. in:

①指令产生模块1,由硬件实现,用于接收所述主动设备提供的启动信号、读/写信号以及I2C设备的设备地址、寄存器地址和要写入寄存器的数据,自动产生访问I2C设备所需的指令,按一定条件和先后顺序送给读写操作执行模块,向所述主动设备返回指令执行情况和从I2C设备读出的数据,并可判断从I2C设备有无响应。① Instruction generation module 1, implemented by hardware, is used to receive the start signal provided by the active device, the read/write signal and the device address of the I2C device, the register address and the data to be written into the register, and automatically generate the data required for accessing the I2C device. The instructions are sent to the read and write operation execution module according to certain conditions and sequence, and the execution status of the instructions and the data read from the I2C device are returned to the active device, and whether there is a response from the I2C device can be judged.

本模块包含命令控制寄存器11、设备地址寄存器12、寄存器地址寄存器13、写入数据寄存器14、读出数据寄存器15及分频设置寄存器16,其中:This module includes command control register 11, device address register 12, register address register 13, write data register 14, read data register 15 and frequency division setting register 16, among which:

命令控制寄存器11,用于发动对I2C设备读或写,为3位W/R寄存器,各比特位的功能如下:The command control register 11 is used to start reading or writing to the I2C device. It is a 3-bit W/R register. The functions of each bit are as follows:

BIT0=1写I2C设备使能,当执行完写操作后,该比特位自动清零;BIT0=1 write I2C device enable, when the write operation is completed, the bit is automatically cleared;

BIT1=1读I2C设备使能,当执行完读操作后,该比特位自动清零;BIT1=1 read I2C device enable, when the read operation is completed, the bit is automatically cleared;

BIT2=1在执行读或写的操作中,有错误出现,表示没有正确地执行完读、写操作;BIT2=1 During the execution of the read or write operation, an error occurs, indicating that the read or write operation has not been completed correctly;

BIT2=0正常。BIT2=0 is normal.

设备地址寄存器12,用于存储要访问的I2C设备的设备地址,为7位W/R寄存器,对应于图6中的DEVICE ADDRESS;Device address register 12, used to store the device address of the I2C device to be accessed, is a 7-bit W/R register, corresponding to DEVICE ADDRESS among Fig. 6;

寄存器地址寄存器13,用于存储要访问I2C设备的寄存器的地址,为8位W/R寄存器,对应图6中的WORD ADDRESS;Register address register 13, used to store the address of the register to be accessed by the I2C device, is an 8-bit W/R register, corresponding to WORD ADDRESS in Figure 6;

写入数据寄存器14,用于存储要写的数据,为8位W/R寄存器;Write data register 14, be used for storing the data to be written, be 8 W/R registers;

读出数据寄存器15,用于存储读出的数据,为8位R寄存器;The read data register 15 is used to store the read data and is an 8-bit R register;

分频设置寄存器16,用于设置送出的SDA/SCL信号的频率与输入的CLK频率之间的倍数关系,为8位W/R寄存器,CLK的最小值不能低于10MHz。The frequency division setting register 16 is used to set the multiple relationship between the frequency of the SDA/SCL signal sent and the frequency of the input CLK. It is an 8-bit W/R register, and the minimum value of CLK cannot be lower than 10MHz.

计算公式为:The calculation formula is:

这6个寄存器的地址分别是:0、1、2、3、4、5。The addresses of these six registers are: 0, 1, 2, 3, 4, 5.

这个模块是本发明装置与主动设备(比如CPU)的接口模块。主动设备通过一个通用的异步访问总线与该模块相接,异步访问总线的信号可参见图1,表1给出了异步接口信号的说明。This module is an interface module between the device of the present invention and active equipment (such as CPU). The active device is connected to the module through a common asynchronous access bus. The signals of the asynchronous access bus can be seen in Figure 1. Table 1 shows the description of the asynchronous interface signals.

表1   信号名称   解释   Data bus   数据总线。(I/O)   CLK   时钟,本发明正常工作必需的时钟信号。In   CS   片选信号,低电平有效。In   WR   读写信号,低代表写,高代表读。In   Reset   复位信号,低电平有效。正常工作时必须为高。In   INT   中断输出,0表示读、写操作完成,1未完成或没有读、写操作,读本发明的寄存器E可清该中断。Out   A[2:0]   地址总线,要访问指令产生模块的某个寄存器,该总线必须有正确的地址指示。In Table 1 signal name explain Data bus Data Bus. (I/O) CLK Clock, the clock signal necessary for the normal operation of the present invention. In CS Chip select signal, active low. In WR Read and write signals, low for writing, high for reading. In Reset Reset signal, active low. Must be high for normal operation. In INT Interrupt output, 0 means that the read and write operation is completed, 1 is not completed or there is no read and write operation, and the interrupt can be cleared by reading the register E of the present invention. out A[2:0] Address bus, to access a certain register of the instruction generating module, the bus must have the correct address indication. In

图2,图3示出了上述部分异步接口信号在写和读操作时的传输时序,图中的主动设备4和指令产生模块之间的总线可以是CPU的local bus(本地设备总线,BOOT;FLASH等的访问总线),Power PC(motorola的Power PCCPU系列),单片机(51系列),interl CPU的ISA(Industry Standard Architecture工业标准结构)总线,MIPS CPU的device总线等,任何满足图2,图3时序的异步访问总线都可与本发明对接,直接使用本发明。图中:Fig. 2, Fig. 3 have shown the transmission sequence of above-mentioned part asynchronous interface signal when writing and reading operation, and the bus between active equipment 4 in the figure and instruction generation module can be the local bus (local equipment bus, BOOT; access bus such as FLASH), Power PC (Power PCCPU series of motorola), single-chip microcomputer (51 series), ISA (Industry Standard Architecture industry standard structure) bus of interl CPU, device bus of MIPS CPU, etc. All the asynchronous access buses of 3 timings can be connected with the present invention, and the present invention can be used directly. In the picture:

Tw-we的时间长度可以不定,只要在有效的写周期(CS=0 and wr=0,data bus和A[2:0]有效)内,有一CLK的上升沿即可;The time length of Tw-we can be indefinite, as long as there is a rising edge of CLK in the valid write cycle (CS=0 and wr=0, data bus and A[2:0] are valid);

Tw-rd的时间长度可以不定,可以大于10纳秒;The time length of Tw-rd can be variable and can be greater than 10 nanoseconds;

Twr-w和Tcs-w可以相等,也可以不等;Twr-w and Tcs-w can be equal or not;

Twr-r和Tcs-r的关系,要满足Twr-r≥Tcs-r。The relationship between Twr-r and Tcs-r must satisfy Twr-r≥Tcs-r.

其中字符段含义如下:The meanings of the character fields are as follows:

Tw-we主动设备访问本发明写操作的访问周期时间。Tw-we active device accesses the access cycle time of the write operation of the present invention.

Twr-w主动设备访问本发明写操作的访问周期中的写信号有效时间。The Twr-w active device accesses the effective time of the write signal in the access period of the write operation of the present invention.

Tcs-w主动设备访问本发明写操作的访问周期中的片选信号有效时间。The Tcs-w active device accesses the effective time of the chip selection signal in the access period of the write operation of the present invention.

Tw-rd主动设备访问本发明读操作的访问周期时间。The Tw-rd active device accesses the access cycle time of the read operation of the present invention.

Twr-r主动设备访问本发明读操作的访问周期中的写信号无效时间。The Twr-r active device accesses the invalid time of the write signal in the access period of the read operation of the present invention.

Tcs-r主动设备访问本发明读操作的访问周期中的片选信号有效时间。The Tcs-r active device accesses the effective time of the chip selection signal in the access period of the read operation of the present invention.

②读写操作执行模块2,用于根据所述指令产生模块1的指令,遵照I2C总线协议产生访问I2C设备需要的信号时序,执行对I2C设备的读写操作,并向所述指令产生模块返回指令执行情况。本模块里包含以下几部分:② The read and write operation execution module 2 is used to generate the instructions of the module 1 according to the instructions, follow the I2C bus protocol to generate the signal timing required for accessing the I2C devices, execute the read and write operations on the I2C devices, and return to the instruction generation module The execution of the order. This module contains the following parts:

命令寄存器21,用于控制START产生模块25、STOP产生单元26、数据发送单元27和数据接收单元28的启动。其受控于指令产生模块1,指令产生模块1通过设置本寄存器的不同比特位,从而达到控制读写操作执行模块工作的目的,START产生模块25、STOP产生单元26、数据发送单元27和数据接收单元28四个模块不能同时工作。本实施例中:The command register 21 is used to control the startup of the START generating module 25 , the STOP generating unit 26 , the data sending unit 27 and the data receiving unit 28 . It is controlled by the instruction generation module 1, and the instruction generation module 1 achieves the purpose of controlling the work of the read and write operation execution module by setting different bits of the register, the START generation module 25, the STOP generation unit 26, the data sending unit 27 and the data The four modules of the receiving unit 28 cannot work simultaneously. In this example:

BIT0=1 START产生单元25工作使能,START产生单元将图8中的开始时序(start condition)发送到I2C总线上,操作完成后,将该BIT位清0;BIT0=1 START generation unit 25 is enabled, and the START generation unit sends the start sequence (start condition) in Figure 8 to the I2C bus. After the operation is completed, the BIT position is cleared to 0;

BIT1=1发送数据模块27工作使能,当发送数据模块把发送数据寄存器23里的数据全部发送出,并收到从设备的响应信号后,将该BIT位清0;BIT1=1 send data module 27 work enable, when send data module all send out the data in send data register 23, and after receiving the response signal from equipment, this BIT position is cleared 0;

BIT2=1接收数据模块28工作使能,当接收数据模块把I2C从设备送来的8位数据全部接收下来,并送出响应信号ACK后,自动将该BIT位清0;BIT2=1 receiving data module 28 is enabled, when the receiving data module receives all the 8-bit data sent by I2C from the device, and sends the response signal ACK, the BIT bit is automatically cleared to 0;

BIT3=1STOP产生单元26工作使能,STOP产生模块将图8中的结束时序(stop condition)发送到I2C总线上,操作完成后,将该BIT位清0。BIT3=1STOP generation unit 26 work enables, and STOP generation module sends the end sequence (stop condition) among Fig. 8 on the I2C bus, and after the operation is completed, this BIT position is cleared to 0.

接收数据寄存器22,用于缓存数据接收单元28接收到的数据;The receiving data register 22 is used for buffering the data received by the data receiving unit 28;

发送数据寄存器23,缓存数据发送单元27将要发送的数据;send data register 23, cache the data to be sent by data sending unit 27;

时钟产生单元24,用于产生读写操作执行模块中各模块所需的时钟;A clock generating unit 24, configured to generate the clocks required by each module in the read and write operation execution module;

START产生单元25,用于产生I2C总线协议中规定的START时序;(图8中的start condition开始条件)START generation unit 25 is used to generate the START timing specified in the I2C bus protocol; (the start condition start condition in Fig. 8)

STOP产生单元26,用于产生I2C总线协议中规定的STOP时序;(图8中的stop condition结束条件)STOP generation unit 26 is used to generate the STOP timing specified in the I2C bus protocol; (stop condition termination condition among Fig. 8)

数据发送单元27,用于依照I2C总线协议规定的SDA、SCL的时序,将发送数据寄存器23中的数据,发送到I2C总线上;The data sending unit 27 is used to send the data in the sending data register 23 to the I2C bus according to the timing of SDA and SCL stipulated in the I2C bus protocol;

数据接收单元28,用于依照I2C总线协议规定的SDA、SCL的时序,接收I2C总线上的数据。The data receiving unit 28 is configured to receive data on the I2C bus according to the timing of SDA and SCL stipulated in the I2C bus protocol.

基于以上装置,图4A和图4B所示是本发明实施例的主动设备访问指令产生模块设备的流程图,其中写操作的流程如图4A所示,包括以下步骤:Based on the above device, Fig. 4A and Fig. 4B are the flowcharts of the active device access instruction generation module device according to the embodiment of the present invention, wherein the process of writing operation is as shown in Fig. 4A, including the following steps:

步骤100,主动设备设置指令产生模块里的设备地址寄存器,将要访问的I2C设备的地址,写入该寄存器;Step 100, the active device setting instruction generates the device address register in the module, and writes the address of the I2C device to be accessed into the register;

步骤110,主动设备设置指令产生模块里的寄存器地址寄存器,将要访问的I2C设备寄存器的地址,写入该寄存器;Step 110, the active device setting command generates the register address register in the module, and writes the address of the I2C device register to be accessed into the register;

步骤120,主动设备设置指令产生模块里的写入数据寄存器,将要写入的数据,写入该寄存器;Step 120, write the data to be written into the register in the write data register in the active device setting instruction generation module;

步骤130,主动设备设置指令产生模块的命令控制寄存器中启动写操作的相应BIT位,本实施例中,写操作时设置BIT0=1;Step 130, the active device sets the corresponding BIT bit to start the write operation in the command control register of the instruction generation module. In this embodiment, set BIT0=1 during the write operation;

步骤140,主动设备等待中断报出(INT信号变化),或者判断所述命令控制寄存器的BIT0位是否变为0,若变为0,则操作正确完成,则可以进行下次操作了;若命令控制寄存器的错误指示BIT位有错误指示,则操作未正确执行完成,主动设备要进行错误处理操作,比如,重新执行上一操作或作其它处理;若操作未完成,则等待本操作完成。Step 140, the active device waits for an interrupt to report (INT signal changes), or judges whether the BIT0 bit of the command control register becomes 0, if it becomes 0, then the operation is correctly completed, and the next operation can be carried out; if the command If there is an error indication in the error indication BIT bit of the control register, the operation is not completed correctly, and the active device will perform error handling operations, such as re-executing the previous operation or doing other processing; if the operation is not completed, then wait for the completion of the operation.

如果下一次操作,与上一次操作访问的是同一I2C设备,则直接返回到步骤110;如果不是同一I2C设备,则要返回到步骤100。If the next operation accesses the same I2C device as the previous operation, then directly return to step 110; if not the same I2C device, then return to step 100.

从上面可以看出,对于单个I2C设备,主动设备只需要4步操作即可完成对I2C设备的一次写操作,其中步骤100、110和130是设置启动一次访问I2C设备必需的步骤。It can be seen from the above that for a single I2C device, the active device only needs 4 steps to complete a write operation to the I2C device, and steps 100, 110 and 130 are necessary steps for setting and starting an access to the I2C device.

读操作的流程如图4B所示,包括以下步骤:The flow of the read operation is shown in Figure 4B, including the following steps:

步骤200,主动设备设置指令产生模块里的设备地址寄存器,将要访问的I2C设备的地址,写入该寄存器;Step 200, write the address of the I2C device to be accessed into the device address register in the active device setting instruction generation module;

步骤210,主动设备设置指令产生模块里的寄存器地址寄存器,将要访问的I2C设备寄存器的地址,写入该寄存器;Step 210, write the address of the I2C device register to be accessed into the register address register in the active device setting instruction generating module;

步骤220,主动设备设置指令产生模块里的命令控制寄存器中启动读操作的相应BIT位,本实施例中,读操作时设置BIT1=1;Step 220, the active device sets the corresponding BIT bit that starts the read operation in the command control register in the instruction generation module. In this embodiment, set BIT1=1 during the read operation;

步骤230,主动设备通过和写操作相同的方式判断操作是否正确完成,如果是,执行下一步,否则继续等待或进行错误处理;Step 230, the active device judges whether the operation is completed correctly in the same way as the write operation, if yes, execute the next step, otherwise continue to wait or perform error handling;

步骤240,主动设备读指令产生模块里读出数据寄存器,取想要的结果,然后可进行下一次操作。In step 240, the active device reads the instruction generating module to read the data register, obtains the desired result, and then proceeds to the next operation.

如果下一次操作,与上一次操作访问的是同一I2C设备,则直接返回到步骤210;如果不是同一I2C设备,则要返回到步骤200。If the next operation accesses the same I2C device as the previous operation, then directly return to step 210; if not the same I2C device, then return to step 200.

从上面可以看出,对于单个I2C设备,主动设备只需要3步操作即可完成对I2C设备的读操作。不象现有的技术,主动设备需要15步的操作和判断,才可完成对一个I2C设备的读操作。It can be seen from the above that for a single I2C device, the active device only needs 3 steps to complete the read operation of the I2C device. Unlike the existing technology, the active device needs 15 steps of operation and judgment to complete the read operation of an I2C device.

图7是指令产生模块工作的流程图,包括以下步骤:Fig. 7 is the flowchart of instruction generation module work, comprises the following steps:

步骤300,指令产生模块实时监测本模块的命令控制寄存器的BIT0和BIT1位的值,如果BIT0=1,执行步骤310~360的写操作流程,BIT1=1,执行步骤400以下的读操作流程,否则继续检测;Step 300, the instruction generation module real-time monitors the value of the BIT0 and BIT1 bits of the command control register of this module, if BIT0=1, execute the write operation process of steps 310~360, BIT1=1, execute the read operation process below step 400, Otherwise, continue to detect;

步骤310,向读写操作执行模块发送START指令(I2C总线的开始标志,对应图8中的start condition);Step 310, send the START command (the start sign of I2C bus, corresponding to the start condition in Figure 8) to the read and write operation execution module;

步骤320,向读写操作执行模块发送DEVICE ADDRESS(I2C设备地址)及写指示;Step 320, sending DEVICE ADDRESS (I2C device address) and writing instructions to the read and write operation execution module;

步骤330,向读写操作执行模块发送WORD ADDRESS指令(I2C设备的寄存器地址);Step 330, send WORD ADDRESS instruction (the register address of I2C equipment) to read and write operation execution module;

步骤340,向读写操作执行模块发送数据(DATA);Step 340, sending data (DATA) to the read and write operation execution module;

步骤350,向读写操作执行模块发送STOP指令(I2C总线的结束标志,对应图8中的stop condition);Step 350, send a STOP instruction (the end sign of I2C bus, corresponding to the stop condition in Figure 8) to the read and write operation execution module;

步骤360,所有指令正确完成后,清命令控制寄存器的BIT0=0,同时产生中断送INT信号,告知主动设备写操作完成,结束一次写操作;Step 360, after all instructions are correctly completed, clear the BIT0=0 of the command control register, generate an interrupt and send the INT signal simultaneously, inform the active device that the write operation is completed, and end a write operation;

步骤400,向读写操作执行模块发送START指令;Step 400, sending a START command to the read and write operation execution module;

步骤410,向读写操作执行模块发送DEVICE ADDRESS及写指示;Step 410, send DEVICE ADDRESS and write instructions to the read and write operation execution module;

步骤420,向读写操作执行模块发送WORD ADDRESS指令;Step 420, send the WORD ADDRESS command to the read and write operation execution module;

步骤430,向读写操作执行模块发送STOP指令;Step 430, sending a STOP command to the read and write operation execution module;

步骤440,启动10ms延时;Step 440, start a 10ms delay;

步骤450,向读写操作执行模块发送START指令;Step 450, sending a START instruction to the read and write operation execution module;

步骤460,向读写操作执行模块发送DEVICE ADDRESS及读指示;Step 460, sending DEVICE ADDRESS and read instructions to the read and write operation execution module;

步骤470,向读写操作执行模块发送指令,置SDA为高阻,并准备接收从I2C设备的数据;Step 470, sending instructions to the read and write operation execution module, setting SDA as high impedance, and preparing to receive data from the I2C device;

步骤480,数据接收完毕后,向读写操作执行模块发送STOP指令;Step 480, after the data is received, send a STOP instruction to the read and write operation execution module;

步骤490,所有指令正确完成后,清命令控制寄存器的BIT1=0,同时产生中断INT信号,告知主动设备读操作完成,结束一次读操作。Step 490, after all the instructions are completed correctly, clear the BIT1=0 of the command control register, and at the same time generate an interrupt INT signal to inform the active device that the read operation is completed, and end a read operation.

上述步骤中,指令产生模块向读写操作执行模块发送完一个指令后,同时启动时间计时,本模块的每一个指令都设计一个故障告警最大时间值,当计时的时间达到这个值还没有检测到本操作正确执行完成,则认为出现故障,终止本次读、写操作,置故障指示位(将命令控制寄存器BIT2置1),步骤500,指示出现错误,告知主动设备写操作不成功;如本次读写操作不能正确完成,将终止本次读、写操作,并用故障指示位告知主动设备本次操作失败,由主动设备决定再如何进行下一步操作。In the above steps, after the command generation module sends a command to the read and write operation execution module, it starts time timing at the same time. Each command of this module is designed with a maximum time value of fault alarm. When the time counted reaches this value, it has not yet detected This operation is correctly carried out, then it is considered that there is a fault, terminate this read and write operation, set the fault indication bit (set the command control register BIT2 to 1), step 500, indicate that an error occurs, and inform the active device that the write operation is unsuccessful; If the read and write operation cannot be completed correctly, the read and write operation will be terminated, and the active device will be informed of the failure of this operation with the fault indicator bit, and the active device will decide how to proceed to the next step.

是否正确执行完成的判断方法是:由于读写操作执行模块每执行完成一个指令,都清该模块命令寄存器的相应BIT位。并把命令寄存器的几个控制BIT位通过error信号(参见图1)送给指令产生模块,具体实施是:error[3:0]=BIT[3:0],BIT[3:0]是命令寄存器的BIT位。因而,指令产生模块通过检测error[x]的值,即可得知本次指令是否正确操作完成。The judging method of whether the execution is completed correctly is: because the read and write operation execution module executes an instruction every time, the corresponding BIT bit of the command register of the module is cleared. And several control BIT bits of the command register are sent to the instruction generation module through the error signal (see Fig. 1), and the specific implementation is: error[3:0]=BIT[3:0], BIT[3:0] is the command The BIT bit of the register. Therefore, the command generating module can know whether the correct operation of this command is completed by detecting the value of error[x].

上述指令产生模块在写操作和读操作时的时序分别如图6和图7所示,检测到主动设备要写一个I2C设备时,指令产生模块将依照图6的顺序依次发送START->发送DEVICE ADDRESS及写指示->发送WORDADDRESS->发送数据->发送STOP;检测到主动设备要读一个I2C设备时,依照图7的顺序依次发送START->发送DEVICE ADDRESS及写指示->发送WORD ADDRESS->发送STOP->发送START->发送DEVICEADDRESS及读指示->接收数据->发送STOP。The timing of the above-mentioned command generation module in the write operation and read operation is shown in Figure 6 and Figure 7 respectively. When it is detected that the active device wants to write an I2C device, the command generation module will send START->send DEVICE in sequence according to the order of Figure 6 ADDRESS and write instruction->send WORDADDRESS->send data->send STOP; when detecting that the active device wants to read an I2C device, send START->send DEVICE ADDRESS and write instruction->send WORD ADDRESS- >Send STOP->Send START->Send DEVICEADDRESS and read instructions->Receive data->Send STOP.

图7中,除DATA部分是由I2C从设备(即图1中的I2C设备)送出并由本发明接收外,其他部分都是(除ACK)都是由本发明送出的。图中MSB表示字节的高位BIT,LSB表示字节的低位BIT,W/R为读写指示,指示本周期是读I2C设备还是写I2C设备,0写,1读。有需要判断从设备响应的地方(比如:本发明的读写操作执行模块,发送完DEVICE ADDRESS及读写指示R/W后,就要判断I2C设备送回的ACK信号,(正确的ACK信号应为1个时钟周期的低电平0)若检查到这个ACK信号,读写操作执行模块则认为本次指令正确执行完成)读写操作执行模块通过检测图6,图7中的ACK信号自动完成的,ACK为0表示从设备有回应,ACK为1表示从设备无回应,等同图8中的ACK周期。In Fig. 7, except that the DATA part is sent by the I2C slave device (ie the I2C device in Fig. 1) and received by the present invention, other parts (except ACK) are all sent by the present invention. In the figure, MSB represents the high-order BIT of the byte, LSB represents the low-order BIT of the byte, and W/R is the read and write indicator, indicating whether to read or write the I2C device in this cycle, 0 for writing, 1 for reading. There is a place where it is necessary to judge the response from the device (for example: the read-write operation execution module of the present invention, after sending DEVICE ADDRESS and read-write indication R/W, will judge the ACK signal sent back by the I2C device, (the correct ACK signal should be It is a low level of 1 clock cycle 0) If the ACK signal is detected, the read and write operation execution module considers that the instruction has been executed correctly.) The read and write operation execution module automatically completes by detecting the ACK signal in Figure 6 and Figure 7 Yes, ACK is 0 means that the slave device has a response, and ACK is 1 means that the slave device has no response, which is equivalent to the ACK cycle in Figure 8.

下面描述一下读写操作执行模块根据指令产生模块的指令,按I2C总线协议产生访问I2C设备需要的信号时序,执行对I2C设备的读写操作的情况。The following describes the situation that the read and write operation execution module generates the instructions of the module according to the instructions, generates the signal timing required to access the I2C device according to the I2C bus protocol, and executes the read and write operations on the I2C device.

图8描述了I2C总线的传输时序。I2C总线包括两根信号线,一条是数据信号SDA,另一是时钟信号SCL,每一个数据比特对应一个完整时钟1周期,时钟信号SCL为1时,数据SDA不能有变化,若有变化则被认为成开始(START,图8中的start condition)或结束(STOP,图8中的stopcondition)标志。当SCL=1,SDA有下降沿是“开始”;当SCL=1,SDA有上升沿是“结束”。占用I2C总线的设备为主设备,被访问的设备是从设备。主设备每传输一个字节(8BIT),从设备在SCL的第9个CLOCK就应有一个低电平的回应(从设备把SDA拉低一个时钟周期)(图8中的ACK),若主设备检测不到这个“回应”,则数据传输不成功。数据传输顺序是以高位(MSB)开始,低位(LSB)结束。Figure 8 describes the transmission timing of the I2C bus. The I2C bus includes two signal lines, one is the data signal SDA, and the other is the clock signal SCL. Each data bit corresponds to a complete clock cycle. When the clock signal SCL is 1, the data SDA cannot change. If there is a change, it will be blocked. Think of it as a start (START, start condition in Figure 8) or end (STOP, stopcondition in Figure 8) flag. When SCL=1, the falling edge of SDA is "start"; when SCL=1, the rising edge of SDA is "end". The device occupying the I2C bus is the master device, and the accessed device is the slave device. Every time the master device transmits a byte (8BIT), the slave device should respond with a low level at the 9th CLOCK of SCL (the slave device pulls SDA low for one clock cycle) (ACK in Figure 8), if the master device If the device cannot detect this "response", the data transmission is unsuccessful. The data transmission sequence starts with the high bit (MSB) and ends with the low bit (LSB).

本实施例的读写操作执行模块需要根据指令产生模块的指令产生所需的I2C总线的传输时序。如图1所示,指令产生模块1和读写操作执行模块2之间通过异步总线连接。各信号的含义如表2所示:The read and write operation execution module of this embodiment needs to generate the required transmission timing of the I2C bus according to the instructions of the instruction generation module. As shown in FIG. 1 , the instruction generation module 1 and the read and write operation execution module 2 are connected through an asynchronous bus. The meaning of each signal is shown in Table 2:

表2   reset   复位信号。   clock   读写操作执行模块正常工作必需的时钟信号。   WE   写使能信号,低电平有效。该信号低时,Data_i总线上的数据有效。   Data_i   数据总线输入,指令产生模块送往读写操作执行模块。   Data_o   数据总线输出,读写操作执行模块送往指令产生模块。   Txreg_cs   发送数据寄存器选择信号。   Comd_cs   命令寄存器选择信号。   Error[3:0]   错误指示信号,用于指示某一操作是否正确执行完成。 Table 2 reset reset signal. clock Clock signal necessary for the proper functioning of the module by performing read and write operations. we Write enable signal, active low. When this signal is low, the data on the Data_i bus is valid. Data_i The data bus is input, and the instruction generation module sends the read and write operation execution module. Data_o The data bus output is sent to the command generation module by the read and write operation execution module. Txreg_cs Send data register select signal. Comd_cs Command register select signal. Error[3:0] The error indication signal is used to indicate whether an operation has been performed correctly.

通过以上信号即可完成两个模块间的访问控制,例如,在指令产生模块发送DEVICE ADDRESS指令时,WE和Txreg_cs信号有效,指令产生模块设备地址寄存器中的设备地址通过Data_i写到读写操作执行模块里的发送数据寄存器,然后,指令产生模块再通过Comd_cs信号设置读写操作执行模块的命令寄存器的BIT1=1,读写操作执行模块检测到命令寄存器的BIT1=1,启动发送数据模块工作,把发送数据寄存器的值送到I2C总线上。完成本操作后,清掉命令寄存器的BIT1,指令产生模块检测到读、写操作执行模块的命令寄存器的BIT1恢复成0,得知上一操作已完成,开始下一操作。其它指令的具体操作与此类似,在此就不一一细述。The access control between the two modules can be completed through the above signals. For example, when the command generation module sends the DEVICE ADDRESS command, the WE and Txreg_cs signals are valid, and the device address in the device address register of the command generation module is written to the read and write operations through Data_i. The sending data register in the module, then, the command generation module sets the BIT1=1 of the command register of the read and write operation execution module through the Comd_cs signal, and the read and write operation execution module detects the BIT1=1 of the command register, and starts the work of the sending data module, Send the value of the send data register to the I2C bus. After completing this operation, clear the BIT1 of the command register, and the command generating module detects that the BIT1 of the command register of the read and write operation execution module returns to 0, knowing that the previous operation has been completed, and starts the next operation. The specific operations of other instructions are similar to this and will not be detailed here.

综上所述,由于指令产生模块和读写操作执行模块都是由硬件实现,所以,整个I2C设备的访问过程基本没有CPU参与,CPU所做的只是提供给两个模块完成访问I2C设备必须的条件。所以本方法解决了现有技术中访问I2C设备对软件的过分依赖。To sum up, since the instruction generation module and the read and write operation execution module are implemented by hardware, the entire I2C device access process basically does not involve the CPU. condition. Therefore, this method solves the excessive dependence on software for accessing I2C devices in the prior art.

Claims (15)

1, a kind of device of realizing automatic reading and writing internal integrated device electronics, it is characterized in that, comprise with hard-wired command generation module and read-write operation execution module, described command generation module links to each other with active devices and described read-write operation execution module respectively by the asynchronous access bus, described read-write operation execution module links to each other with internal integrated circuit equipment by internal integrate circuit bus, wherein:
Described command generation module, be used to receive device address, the register address of enabling signal, read/write signal and internal integrated circuit equipment that described active devices provides and will write the data of register, automatically produce the required instruction of visit internal integrated circuit equipment, deliver to described read-write operation execution module in regular turn, and to described active devices link order implementation status and integrated device electronics data of reading internally;
Described read-write operation execution module, be used for instruction according to described command generation module, abide by the internal integrate circuit bus agreement and produce the signal sequence that visit internal integrated circuit equipment needs, execution is to the read-write operation of inner integrated device electronics, and to described command generation module link order implementation status.
2, device as claimed in claim 1, it is characterized in that, described command generation module sends sign on, device address instruction successively and writes indication, register address instruction, data command and halt instruction when detecting active devices and will write an internal integrated circuit equipment.
3, device as claimed in claim 1, it is characterized in that, described command generation module sends sign on, device address instruction successively and writes indication, register address instruction, halt instruction, sign on, device address instruction and read indication, reception data command and halt instruction when detecting active devices and will read an internal integrated circuit equipment.
4, device as claimed in claim 1 is characterized in that, described command generation module comprises:
The order control register by the value that the enabling signal and the read/write signal of described active devices is provided with corresponding control bit, starts inner integrated device electronics is read or write, and when carrying out failure error flag is set;
Device address register, the device address that is used to store the internal integrated circuit equipment that will visit;
The register address register, the address that is used to store the register of the internal integrated circuit equipment that will visit:
Write data register, be used to store the data that to write;
Read data register is used to store the data that will read;
Frequency division is provided with register, is used to be provided with the multiple relation between the CLK frequency of the frequency of the SDA/SCL signal of sending and input;
Described active devices is selected above-mentioned register by the address signal of asynchronous access bus.
5, device as claimed in claim 4, it is characterized in that, described command generation module is after finishing a read or write look-at-me to be set to described active devices link order implementation status, perhaps after the order control register executes operation with corresponding bit automatic clear, perhaps the combination by above dual mode realizes.
6, device as claimed in claim 1, it is characterized in that, described read-write operation execution module comprises command register, receive data register, transmitting data register, clock generating unit, START generation unit, STOP generation unit, data transmission unit and Data Receiving unit, wherein:
Described command register, the value of corresponding control bit is set by the instruction of described command generation module, control the startup of described START generation unit, STOP generation unit, data transmission unit and Data Receiving unit, and the operation complete after with the corresponding positions zero clearing;
Described receive data register is used for the data that data cached receiving element receives;
Described transmitting data register is used for the data that data cached transmitting element will send;
Clock generating unit is used for producing the required clock of each module of read-write operation execution module;
Described START generation unit is used for producing the START sequential that the internal integrate circuit bus agreement is stipulated;
Described STOP generation unit is used for producing the STOP sequential that the internal integrate circuit bus agreement is stipulated;
Described data transmission unit is used for according to the SDA of internal integrate circuit bus agreement regulation, the sequential of SCL the data in the described transmitting data register being sent on the internal integrate circuit bus;
Described Data Receiving unit is used for receiving the data on the internal integrate circuit bus according to the SDA of internal integrate circuit bus agreement regulation, the sequential of SCL.
7, device as claimed in claim 6, it is characterized in that, asynchronous access bus between described command generation module and the read-write operation execution module comprises reset signal, clock signal, writes enable signal, transmitting data register is selected signal, command register is selected signal, data bus input and output signal, and the circuit of error indication signal, described error indication signal is produced by the control bit of described command register, is used for to described command generation module link order implementation status.
8, a kind of method that realizes writing automatically internal integrated circuit equipment is applied to active devices by in hard-wired command generation module and write operation execution module and the system that internal integrate circuit bus links to each other, and this method may further comprise the steps:
(a) address of the internal integrated circuit equipment that will visit of described active devices writes the device address register of described command generation module;
(b) address of the internal integrated circuit device register that will visit of described active devices writes the register address register of described command generation module;
(c) the described active devices data that will write write the data register that writes of described command generation module;
(d) described active devices is provided with the corresponding BIT position startup write operation of order control register in the described command generation module;
(e) described command generation module produces automatically and writes the required instruction of internal integrated circuit equipment, delivers to described write operation execution module in regular turn;
(f) described write operation execution module is abideed by the generation of internal integrate circuit bus agreement and is write the signal sequence of internal integrated circuit equipment and finish write operation, the link order implementation status according to the instruction of described command generation module;
(g) described command generation module is to described active devices link order implementation status;
(h) after described active devices decision operation is correctly finished, finish one time write operation.
9, method as claimed in claim 8 is characterized in that, after the described step (h), if next operation and last operational access is same internal integrated circuit equipment, then directly returns step (b), otherwise returns step (a).
10, method as claimed in claim 8 is characterized in that, in the described step (e), described command generation module sends sign on, device address instruction successively and writes indication, register address instruction, data command and halt instruction.
11, method as claimed in claim 8 is characterized in that, in the described step (h), described active devices is quoted by the interruption of described command generation module, perhaps detects the value of the corresponding control bit of described command generation module and confirms whether operation is correctly finished; The value of the error indication bit by detecting described command generation module judges whether to carry out the fault processing operation.
12, a kind of method that realizes reading automatically internal integrated circuit equipment is applied to active devices by in hard-wired command generation module and read operation execution module and the system that internal integrate circuit bus links to each other, and this method may further comprise the steps:
(a) address of the internal integrated circuit equipment that will visit of described active devices writes the device address register of described command generation module;
(b) address of the internal integrated circuit device register that will visit of described active devices writes the register address register of described command generation module;
(c) described active devices is provided with the corresponding BIT position startup read operation of order control register in the described command generation module;
(d) described command generation module produces automatically and reads the required instruction of internal integrated circuit equipment, delivers to described read operation execution module in regular turn;
(e) described read operation execution module is abideed by the generation of internal integrate circuit bus agreement and is read the signal sequence of internal integrated circuit equipment and finish read operation according to the instruction of described command generation module, and the link order implementation status;
(f) described command generation module is returned data and the condition execution instruction of reading to described active devices;
(g) after described active devices decision operation is correctly finished,, finish a read operation from described command generation module sense data.
13, method as claimed in claim 12 is characterized in that, after the described step (g), if next operation and last operational access is same internal integrated circuit equipment, then directly returns step (b), otherwise returns step (a).
14, method as claimed in claim 12, it is characterized in that, in the described step (d), described command generation module sends sign on, device address instruction successively and writes indication, register address instruction, halt instruction, sign on, device address instruction and read indication, reception data command and halt instruction.
15, method as claimed in claim 12 is characterized in that, in the described step (g), described active devices is quoted by the interruption of described command generation module, perhaps detects the value of the corresponding control bit of described command generation module and confirms whether operation is correctly finished; The value of the error indication bit by detecting described command generation module judges whether to carry out the fault processing operation.
CN 200410000775 2004-01-18 2004-01-18 A device and method for realizing automatic reading and writing of internal integrated circuit equipment Expired - Fee Related CN1292360C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN 200410000775 CN1292360C (en) 2004-01-18 2004-01-18 A device and method for realizing automatic reading and writing of internal integrated circuit equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN 200410000775 CN1292360C (en) 2004-01-18 2004-01-18 A device and method for realizing automatic reading and writing of internal integrated circuit equipment

Publications (2)

Publication Number Publication Date
CN1558332A CN1558332A (en) 2004-12-29
CN1292360C true CN1292360C (en) 2006-12-27

Family

ID=34350502

Family Applications (1)

Application Number Title Priority Date Filing Date
CN 200410000775 Expired - Fee Related CN1292360C (en) 2004-01-18 2004-01-18 A device and method for realizing automatic reading and writing of internal integrated circuit equipment

Country Status (1)

Country Link
CN (1) CN1292360C (en)

Families Citing this family (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100687923B1 (en) * 2005-04-29 2007-02-27 삼성전자주식회사 Master device, control method and electronic device having master device
EP1877911B1 (en) * 2005-04-29 2009-09-23 Nxp B.V. I2c slave/master interface enhancement using state machines
CN101604277B (en) * 2008-06-11 2012-03-28 比亚迪股份有限公司 I<2>C bus verification system and method
CN103186447B (en) * 2011-12-27 2015-02-11 安凯(广州)微电子技术有限公司 Bus read-write detection device
WO2012126425A2 (en) * 2012-05-18 2012-09-27 华为技术有限公司 Data storage system and method
TWI448968B (en) * 2012-07-30 2014-08-11 智原科技股份有限公司 System level simulation and simulation device and method
CN103077139B (en) 2013-02-01 2016-05-11 威盛电子股份有限公司 Integrated circuit using inter-integrated circuit bus and control method thereof
WO2015145347A1 (en) * 2014-03-24 2015-10-01 Inesc Porto- Instituto De Engenharia De Sistemas E Computadores Do Porto Control module for multiple mixed-signal resources management
CN106789507A (en) * 2016-12-19 2017-05-31 北京格林伟迪科技股份有限公司 It is a kind of to realize the method and apparatus that central processing unit communicates with functional chip
CN107168897B (en) * 2017-04-18 2019-12-13 深圳市有芯半导体技术有限公司 Device for realizing I2C repeated read-write control
CN108829626A (en) * 2018-04-26 2018-11-16 常州新途软件有限公司 A kind of communication means for automotive control system
CN110795373B (en) * 2019-09-27 2023-09-19 深圳震有科技股份有限公司 I2C bus-to-parallel bus conversion method, terminal and storage medium
CN111309665B (en) * 2020-02-19 2024-01-02 苏州华兴源创科技股份有限公司 Parallel write operation and read operation control system and method
CN112559275A (en) * 2020-09-08 2021-03-26 中国银联股份有限公司 Integrated circuit, method for maintenance debugging of an integrated circuit and interface circuit
CN112416823B (en) * 2020-11-15 2024-05-03 珠海一微半导体股份有限公司 Sensor data read-write control method, system and chip in burst mode
CN112540944B (en) * 2020-12-15 2022-11-25 安徽皖通邮电股份有限公司 Parallel bus protocol and method for realizing data interaction between boards based on protocol
CN113434442B (en) * 2021-06-30 2025-02-21 新华三信息安全技术有限公司 A switch and data access method
CN113986631B (en) * 2021-10-15 2025-07-29 江南大学 RISC-V oriented debugging module circuit and register reading and writing method
CN114036096B (en) * 2021-11-04 2024-05-03 珠海一微半导体股份有限公司 Read controller based on bus interface
CN114327627B (en) * 2021-12-15 2023-01-03 中国船舶重工集团公司第七0九研究所 Method for configuring display resolution ratio based on GPU traditional IO in real mode
CN114443544B (en) * 2022-04-02 2022-06-28 井芯微电子技术(天津)有限公司 I2C module-based master-slave mode switching method and device
CN116680230B (en) * 2023-05-22 2024-04-09 无锡麟聚半导体科技有限公司 Hardware acceleration circuit and chip
CN116450552B (en) * 2023-06-09 2023-08-29 江苏润石科技有限公司 Asynchronous batch register reading and writing method and system based on I2C bus
CN117201222B (en) * 2023-08-16 2024-06-21 天津瑞发科半导体技术有限公司 I2C interface system, data writing method and data reading method

Also Published As

Publication number Publication date
CN1558332A (en) 2004-12-29

Similar Documents

Publication Publication Date Title
CN1292360C (en) A device and method for realizing automatic reading and writing of internal integrated circuit equipment
CN1053281C (en) Multi-bus system bus bridge for optimum data transfer between system bus and peripheral buses
CN1129852C (en) Universal serial bus device controller
CN1106609C (en) Method and apparatus for configuring multiple agents in a computer system
CN1532666A (en) Information processing device, clock pulse control method and control program of the device
CN1570907A (en) Multiprocessor system
CN1383066A (en) Memory controller and large scale integrated circuit
CN1551592A (en) Data transmission control device, electronic device and data transmission control method
CN101068140A (en) Apparatus and method for realizing primary/standby PCI equipment switchover
CN1947107A (en) Device for transmitting data between memories
CN1591374A (en) Dma transfer controller
CN1617160A (en) Card recognition system for recognizing standard card and non-standard card
CN1234561A (en) Bus-line control method and apparatus and storage medium for storing bus-line control programme
CN1181550A (en) Microprocessor and multiple processors system
CN1763731A (en) cache memory system
CN1607513A (en) Data transfer control device, electronic instrument, and data transfer control method
CN1318242A (en) Data transmission control devices and electronic equipment
CN100346285C (en) Processor chip, storage control system and method
CN1538310A (en) data transmission control device
CN1385793A (en) Data transmission controller, electronic machine and data transmission control method
CN2681233Y (en) Microcomputer with built-in debug function
CN2682491Y (en) Built-in debug function type microcomputer
CN1348648A (en) Data transfer controller, information storage medium, and electronic apparatus
CN1248125C (en) Data transfer control device, program and method of fabricating electronic instrument
CN1109978C (en) Information processing apparatus and method, and scheduling device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C17 Cessation of patent right
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20061227

Termination date: 20140118