Summary of the invention
The object of the invention is to overcome the deficiencies in the prior art, a kind of general slave synchronous serial interface circuit of supporting compatible IIC agreement and SPI protocol bus data transmission is provided.The technical solution used in the present invention is:
A kind of general slave synchronous serial interface circuit comprises:
Initial with stop detection module, for detection of spi bus agreement significance bit, iic bus agreement initial conditions and end condition output;
Control module, for determine the bus data transmission mode of described serial interface circuit according to the initial output signal with the termination detection module, to also string and string modular converter are controlled; Described bus data transmission mode comprises spi bus data transmission and iic bus data transmission;
And string and string modular converter, be controlled by control module, be converted into slave internal register data for a plurality of register data serial output by slave inside and external series data;
Address pointer register, for a plurality of registers of addressing slave inside;
When described serial interface circuit, for the spi bus data transmission time, slave carries out data transmission according to spi bus agreement and main frame;
When described serial interface circuit, for the iic bus data transmission time, slave carries out data transmission according to iic bus agreement and main frame.
Further, described serial interface circuit also comprises chip selection signal port CS_n, serial clock port SCK, serial data port SOI, slave addresses selection port;
When the chip selection signal of described chip selection signal port CS_n is effective, initial and termination detection module sends spi bus agreement significance bit to control module, and described serial interface circuit is for the transmission of SPI total data line;
When the chip selection signal of described chip selection signal port CS_n is invalid, the initial data with stopping detection module detection serial clock port SCK and serial data port SOI, if iic bus agreement initial conditions detected, described serial interface circuit is for the iic bus data transmission; And then, when iic bus agreement end condition being detected, the iic bus data transmission stops;
Described slave addresses selects port for when the iic bus data transmission, determines unique slave addresses of each slave on iic bus.
Further, it is three that described slave addresses is selected port, is respectively that slave addresses is selected port A2, A1 and A0.
Further, described chip selection signal is Low level effective, and high level is invalid.
Further, described iic bus agreement initial conditions are: when the SCK signal is high level, the SOI signal switches to low level from high level; Described iic bus agreement end condition is: when the SCK signal is high level, the SOI signal switches to high level from low level.
Further, when described serial interface circuit for the spi bus data transmission time, according to the register address information comprised in the read write command received and in conjunction with address pointer register, a plurality of registers in slave are carried out to addressing, be specially: control module deposits the register address information comprised in the read write command received in address pointer register, and the register address information that then deposits according to this address pointer register in is carried out addressing to a plurality of registers in slave.
Further, when described serial interface circuit for the iic bus data transmission time, according to the address pointer received and in conjunction with address pointer register, a plurality of registers in slave are carried out to addressing, be specially: control module deposits the address pointer received in address pointer register, and the address pointer that then deposits according to this address pointer register in carries out addressing to a plurality of registers in slave.
The present invention has designed the general slave synchronous serial interface circuit of a kind of compatible IIC and spi bus agreement, and the internal logic resource of having saved interface circuit can also reduce the number of ports of slave interface circuit, can promote the optimal design of whole system.
Embodiment
Below in conjunction with concrete drawings and Examples, the invention will be further described.
A kind of general slave synchronous serial interface circuit comprises: initial and termination detection module 114, for detection of spi bus agreement significance bit, iic bus agreement initial conditions 106 and end condition 110 output; Control module 115, for determine the bus data transmission mode of described serial interface circuit according to the initial output signal with termination detection module 114, to and the string and the string and modular converter 116 controlled, described bus data transmission mode comprises spi bus data transmission and iic bus data transmission; And string and string modular converter 116, be controlled by control module 115, be converted into slave internal register data for a plurality of register data serial output by slave inside and external series data; Address pointer register 117, for a plurality of registers of addressing slave inside.
When described serial interface circuit, for the spi bus data transmission time, slave carries out data transmission according to spi bus agreement and main frame;
When described serial interface circuit, for the iic bus data transmission time, slave carries out data transmission according to iic bus agreement and main frame.
Particularly, slave interface circuit proposed by the invention as shown in Figure 1, comprises with lower interface: chip selection signal port CS_n, serial clock port SCK, serial data port SOI, slave addresses are selected port A2, A1, A0.Wherein, it is defeated that the chip selection signal of chip selection signal end CS_n determines whether to carry out spi bus biography data, Low level effective; Slave addresses selects port A2, A1, A0 for when the iic bus data transmission, determines unique slave addresses of each slave on iic bus.The serial clock terminal that serial clock port SCK, serial data port SOI are iic bus or spi bus and serial data end.
As shown in Figure 2, initial sum stops detection module 114 and send spi bus agreement significance bit to control module 115 when chip selection signal port CS_n is low level circuit structure block diagram of the present invention, and described serial interface circuit is for the transmission of SPI total data line; Otherwise the data of utilizing serial clock port SCK, serial data port SOI when chip selection signal port CS_n is high level whether meet Fig. 5 and Fig. 6 in initial conditions 106 and the stop condition 110 of iic bus agreement judge that whether the iic bus data transmission effective, that is to say the initial data with stopping detection module 114 detection serial clock port SCK and serial data port SOI, if iic bus agreement initial conditions 106 detected, described serial interface circuit is for the iic bus data transmission; And then, when iic bus agreement end condition 110 being detected, the iic bus data transmission stops.Control module 115 stops iic bus agreement initial conditions 106 and the end condition 110 of detection module 114 transmissions according to initial sum or spi bus agreement significance bit is controlled and gone here and there and goes here and there and modular converter 116.When the iic bus data transmission, control module 115 also will receive and send response bits 109 in addition.117 pairs of slave internal registers of host computer using address pointer register carry out addressing, and a plurality of registers in slave inside are carried out to read-write operation.In the present embodiment, in slave, register 1, register 2, register 4, register 5 are read-only register, and the low byte of register 3 is that read-only, high byte is read-write.In this example, slave internal register data are 16 bits.
Above-mentioned iic bus agreement initial conditions 106 are: when the SCK signal is high level, the SOI signal switches to low level from high level; Above-mentioned iic bus agreement end condition 110 is: when the SCK signal is high level, the SOI signal switches to high level from low level.
Wherein, iic bus requires every transmission 8 Bit datas, receives data side and need to send response bits 109 to sending data side.Spi bus does not need to receive or send response bits 109, receives at every turn and send the data of 16 bits.Therefore, in order to meet the needs of iic bus agreement and spi bus agreement, when according to the iic bus agreement, carrying out data transmission, and string and string modular converter 116 utilize is that the register of 8 bits is (to 16 bit register operation the time, can first carry out the operation of high eight-bit, hang down again the operation of eight), and when according to the spi bus agreement, carrying out data transmission, and string and string modular converter 116 utilizations is the register of 16 bits.
Shown in Fig. 3 is the state machine of control module 115.This state machine is initially Idle state 119, when slave receives the spi bus significance bit, be chip selection signal port CS_n while being logical zero, slave enters read data state 124, and next slave enters the read write command state 125 that receives, if read instruction, enter again read data state 124; If write command, enter and write data mode 126.
And when state machine is initially located in Idle state 119, if from machine testing, (initial and termination detection module 114 is being detected, lower same) to iic bus agreement initial conditions 106 and chip selection signal CS_n, be logical one, control module 115 enters into slave addresses and the read-write position receives response status 120, if then slave detects iic bus agreement end condition 110, enter Idle state 119, read sign for iic bus else if, system enters data and sends state 121, if and then slave detects iic bus agreement end condition 110, enter initial Idle state 119; IIC writes sign if, and slave enters address and receives response status 122, and if then slave iic bus agreement end condition 110 detected, slave returns to Idle state 119; Otherwise slave enters data receiver response status 123, and then slave receives iic bus agreement end condition 110, turns back to Idle state 119.
Sequential when general slave synchronous serial interface circuit is used for the spi bus data transmission as shown in Figure 4.When chip selection signal CS_n is effective, at first the read data that slave sends 16 bits to main frame (is the corresponding acquiescence register data of address pointer register 117, initial default data that power on namely), and then the 16 bit read write commands that Receiving Host sends, according to the difference of reading and writing instruction, next 16 clock period slaves send 16 bit read datas or Receiving Host 16 than feature data to main frame.When general slave synchronous serial interface circuit is used for the spi bus data transmission, the corresponding relation of read write command and register is as shown in table 1.Read if instruction, 6,5,4 that read in this example in instruction have represented register address information, 16 6,5,4 of reading instruction that control module 115 will receive deposit address pointer register 117 in, and then slave corresponding register read of register address information from read instruction is fetched data and sent to main frame; Write command if, the middle eight bit data of 16 write commands that control module 115 will receive deposits in the high eight-bit of register 3.Only have register 3 in this example for writing, thus during write operation without according to the addressing of register address information, in the situation that other is possible, when a plurality of registers being arranged for can write the time, the register addressing mode of write operation can be with reference to the addressing mode of read operation.
Table 1
Register |
Read instruction |
Write command |
Register 1 |
1000_0000_0000_0000 |
? |
Register 2 |
1000_0000_0000_1000 |
? |
Register 3 |
1000_0000_0001_0000 |
0000_xxxx_xxxx_0000 |
Register 4 |
1000_0000_0001_1000 |
? |
Register 5 |
1000_0000_0010_0000 |
? |
General slave synchronous serial interface circuit is read sequential as shown in Figure 5 when the iic bus data transmission.In the situation that chip selection signal CS_n is invalid, at first main frame sends iic bus agreement initial conditions 106 to slave, next main frame sends 7 slave addresses 107 and 1 to slave and reads zone bit 108, if slave addresses 107 slave addresses corresponding with this slave addresses selecting side A2-A0 is consistent, slave sends response bits 109 to main frame, next main frame and slave carry out data transmission 130 and reply 131, when slave detects the iic bus agreement end condition 110 of main frame transmission, the iic bus transmission stops.When read operation first, do not need to address pointer register 117 writing address pointers, directly the corresponding acquiescence register data of reading address pointer register 117, namely the initial default data that power on.
General slave synchronous serial interface circuit is write sequential as shown in Figure 6 when the iic bus data transmission.In the situation that chip selection signal CS_n is invalid, at first main frame sends iic bus agreement initial conditions 106 to slave, next main frame sends 7 slave addresses 107 and 1 to slave and writes zone bit 132, if slave addresses 107 slave addresses corresponding with this slave addresses selecting side A2-A0 is consistent, slave sends response bits 109 to main frame, next main frame carries out data transmission 130 and replys 131 with slave again after address pointer register 117 writing address pointer datas 133, in this process, specifically control module 115 deposits the address pointer received in address pointer register 117, control module 115 utilizes address pointer to distinguish the inner different register of slave, with aft engine, slave is carried out to data writing operation, data are written in the corresponding register of address pointer (only has register 3 to write in this example, in other possible situation, other register also can be configured to read-write register).When slave detects the stop condition 110 of main frame transmission, the iic bus transmission stops.The corresponding relation of the register of address pointer and slave inside is as shown in table 2.In the present embodiment, control module 115 deposits in address pointer register 117 low three of the address pointer data 133 that receive, can carry out addressing to five registers.
Table 2
Register |
Address pointer |
Register 1 |
8’b0000_0000 |
Register 2 |
8’b0000_0001 |
Register 3 |
8’b0000_0010 |
Register 4 |
8’b0000_0011 |
Register 5 |
8’b0000_0100 |