A kind of communication between devices method and apparatus topological structure based on spi bus
Technical field
The present invention relates to a kind of fields of communication technology, more particularly, to a kind of communication between devices method based on spi bus
And device topology.
Background technique
SPI (Serial Peripheral Interface, serial peripheral structure) is a kind of high speed, full duplex, synchronous string
Row communication bus.SPI is the serial interface protocol communicated using 4 signal wires, including master/slave both of which, usually
One main equipment and one or more from equipment, wherein 4 signal wires be respectively SCLK signal line (serial clock signal line),
MOSI signal wire (main equipment data output, from device data input signal cable), MISO signal wire (input of main equipment data, from
Device data output signal line) and CS signal wire (chip selection signal line).
Spi bus only takes up four lines on the pin of chip, when main equipment is connected with one from equipment, although can
The pin of chip has been saved, and has saved pcb board space in wiring.But with increasing from equipment, signal wire is more and more, and
And every increase by one is both needed to increase a CS signal wire from equipment, increases wiring space, improves cost.
Summary of the invention
It is an object of the invention to overcome the deficiencies of existing technologies, provide it is a kind of reduce wiring space occupancy based on
The communication between devices method and apparatus topological structure of spi bus.
To achieve the above object, the following technical solutions are proposed: a kind of communication between devices side based on spi bus by the present invention
Method includes the following steps:
Main equipment is sequentially connected in series with several from equipment by step S1 using spi bus, and the spi bus includes
SCLK signal line, MOSI signal wire and MISO signal wire;
Respectively local address is arranged from equipment in step S2, main equipment control;
From data are read from equipment or data are written to from equipment in step S3, main equipment, and main equipment is sent to be believed comprising address
Breath and data information instruction to it is all from the device;
Step S4 judges whether the address information matches with local address from equipment, if matching, thens follow the steps S5,
Otherwise, the data information from equipment parsing described instruction, and it is at bypass condition;
Step S5 send into main equipment from equipment reading Data Concurrent or data is written from equipment.
Preferably, in step s 2, include the following steps: from equipment setting local address
S201, main equipment send setting ontology address command extremely from equipment;
S202, a non-zero values to be received such as when receiving setting local address order from equipment are and non-by this
Zero value is sent to next stage from the device as local address, while after non-zero values are added one.
Preferably, described persistently to send zero when not receiving non-zero values from equipment to next stage from the device.
Present invention further teaches a kind of device topology based on spi bus, including main equipment and several from equipment,
The main equipment and several be sequentially connected in series from equipment by spi bus, the spi bus only include SCLK signal line,
MOSI signal wire and MISO signal wire.
Preferably, it each is equipped with a local address from equipment, the main equipment is by sending setting local address order
To local address is arranged from the device.
Preferably, each it is connected from equipment with an ancillary equipment, is each configured as main equipment from equipment and is set with auxiliary
SPI bridge between standby.
Preferably, when the SPI bridge function from equipment is non-enabled, the address information that will be received from equipment is directly sent out
It send to next stage from the device.
The beneficial effects of the present invention are:
Communication between devices method and apparatus topological structure of the present invention based on spi bus, only with SCLK signal
Line, MOSI signal wire and MISO signal wire by main equipment and several be sequentially connected in series from equipment, and sought by device address
The mode of location realizes the read-write from equipment fixed sum data really, while alloing main equipment in a cycle by bypass technology
Any one in link is inside accessed from equipment, and can be accessed and all be eliminated from equipment in synchronization by broadcast mode
Chip selection signal line, reducing while wiring space occupies ensure that access speed.
Detailed description of the invention
Fig. 1 is communication between devices method flow diagram schematic diagram of the invention;
Fig. 2 is structural block diagram schematic diagram of the invention.
Specific embodiment
Below in conjunction with attached drawing of the invention, clear, complete description is carried out to the technical solution of the embodiment of the present invention.
A kind of disclosed communication between devices method and apparatus topological structure based on spi bus, only with
SCLK (Serial Clock, serial clock) signal wire, (Master Output/Slave Input, main equipment data are defeated by MOSI
Out, inputted from device data) signal wire and MISO (Master Input/Slave Output, main equipment data input, from setting
Standby data export) signal wire by main equipment and several be sequentially connected in series from equipment, and in such a way that device address addresses
The read-write from equipment fixed sum data really is realized, eliminates chip selection signal line, and then reduce the occupancy of wiring space.
As shown in Figure 1, a kind of communication between devices method based on spi bus, includes the following steps:
Main equipment is sequentially connected in series with several from equipment by step S1 using spi bus, and the spi bus includes
SCLK signal line, MOSI signal wire and MISO signal wire;
Specifically, in order to save wiring space, in the present invention, spi bus only takes up three signals on the pin of chip
Line, respectively SCLK signal line, MOSI signal wire and MISO signal wire, and pass through the SCLK signal line, MOSI signal
Line and MISO signal wire by main equipment and several be sequentially connected in series from equipment, eliminate CS (Chip Select, piece choosing) letter
Number line (i.e. chip selection signal line), avoids the problem that one equipment of every increase also increase accordingly a CS signal wire in the prior art,
And then the space of wiring is saved, save cost.Wherein, SCLK signal line be serial clock signal line, serial clock letter by
Main equipment generates;MOSI signal wire is the output of main device data, from device data input signal cable;MISO signal wire is main equipment
Data input, from device data output signal line.
It is finally connected by above-mentioned spi bus and forms topological structure as shown in Figure 2.Wherein, main equipment and first from
Equipment, first from equipment with second from equipment, and so on, N-1 from equipment and n-th from passing through between equipment
The SCLK signal line, MOSI signal wire are connected with MISO signal wire.
Respectively local address is arranged from equipment in step S2, main equipment control;
Specifically, due to eliminating CS signal wire, when determining from equipment, the present invention is in such a way that device address addresses
Realize the determination from equipment.A device address, hereinafter referred to as local address each are all had from equipment, which can be with
It is configured by main equipment.
For it is each from equipment, local address is set when, main equipment can be that each set from equipment by setting ontology address command
Set a local address, wherein the format of setting local address order is as follows:
0xA0- > n*0x00- > 0xMM, MM are address date.
When receiving setting local address order from equipment, should need to wait for receiving a non-zero values from equipment, and
Using the non-zero values as local address, while being exported to next stage from the device after non-zero values are added one.When from equipment not
When receiving non-zero values, always export zero to next stage from the device.
By taking topological diagram shown in Fig. 2 as an example.When main equipment issue setting local address order after, first from equipment first
The order is received, while waiting and receiving a non-zero values, if the non-zero values received are 2, by the non-zero values 2
As first local address from equipment.At the same time, first from equipment will the non-zero values 2 plus one after output to second from
In equipment, i.e., by 3 outputs to second from the device, second regard non-zero values 3 as local address from equipment, and by non-zero values
It exports after 3 plus one to third from the device, and so on, the non-zero values that n-th is received from equipment are N+1, therefore, N
It is a from the local address of equipment be N+1.When it is implemented, local address is indicated with 16 system numbers.
From data are read from equipment or data are written to from equipment in step S3, main equipment, and main equipment is sent to be believed comprising address
Breath and data information instruction to it is all from the device;
Step S4 judges whether the address information matches with local address from equipment, if matching, thens follow the steps S5,
Otherwise, the data information from equipment parsing described instruction, and it is at bypass condition;
Step S5 send into main equipment from equipment reading Data Concurrent or data is written from equipment.
Specifically, main equipment from it is described from equipment read data when, main equipment has determined that from which reads number from the device
According to, main equipment generate the instruction comprising address information and data information to it is all from the device.Topological structure as shown in Figure 2 is adopted
With the mode of series connection, under default situations, it is in bypass (Bypass) state from equipment, within a clock cycle, is owned
Can receive from equipment to main equipment send instruction, from equipment decision instruction address information and local address whether
Match, if mismatching, continue the data information in analyzing the instruction, and continues to keep bypass condition.When from equipment judge address believe
When breath matches with local address, is not continuing to keep bypass condition from equipment, data should obtained simultaneously from memory from equipment
It sends the data in main equipment.
Similarly, for main equipment to when data are written from equipment, main equipment has determined that which reads data from the device, main
Equipment generates the instruction comprising address information and data information to from the device.Under default situations, bypass is in from equipment
(Bypass) state, it is within a clock cycle, all to can receive the instruction sent to main equipment from equipment, judge from equipment
Whether the address information in instruction matches with local address, if mismatching, continues the data information in analyzing the instruction, and continue
Keep bypass condition.When judging that address information and local address match from equipment, do not continuing to keep bypass shape from equipment
State, should write data into from equipment.
In the present embodiment, when being in bypass condition from equipment, the instruction received from equipment is transferred directly to down
One from equipment.
When it is implemented, the transmittable data read from the device that such as give an order of main equipment:
0xAF- > local address- > register address- > register data, wherein local
Address is the local address of the slave equipment of data to be read, i.e. address information;Register address is to deposit in memory
Store up the address of data to be read;Register data is data to be read, i.e. data information.
Similarly, main equipment is transmittable such as issues orders to data are written from the device:
0xAF- > local address- > register address- > register data, wherein local
Address is the local address of the slave equipment of data to be written, i.e. address information;Register address is that storage is to be written
The storage address of data;Register data is data to be written, i.e. data information.
As shown in Fig. 2, present invention further teaches a kind of device topologies based on spi bus, if including main equipment and
Dry from equipment, the main equipment and several be sequentially connected in series from equipment by spi bus, wherein spi bus includes
SCLK signal line, MOSI signal wire and MISO signal wire.
Specifically, spi bus only takes up three signal wires, respectively SCLK signal line, MOSI letter on the pin of chip
Number line and MISO signal wire, and main equipment and several from equipment by the SCLK signal line, MOSI signal wire and
After MISO signal wire is sequentially connected in series, eliminate CS signal wire, avoid in the prior art one equipment of every increase also accordingly increase
The problem of adding a CS signal wire, and then the space of wiring is saved, save cost.
Further, a device address, hereinafter referred to as local address each are all had from equipment, which can be with
It is configured by such as issuing orders:
0xA0- > n*0x00- > 0xMM, MM are address date.
When receiving setting local address order from equipment, should need to wait for receiving a non-zero values from equipment, and
Using the non-zero values as local address, while being exported to next stage from the device after non-zero values are added one.When from equipment not
When receiving non-zero values, always export zero to next stage from the device.
As shown in Fig. 2, first is firstly received the life from equipment after main equipment issues setting local address order
It enables, while waiting and receiving a non-zero values, if the non-zero values received are 1, regard the non-zero values 1 as first
From the local address of equipment.At the same time, it first will be exported from equipment to second from the device, i.e., after the non-zero values 1 plus one
From the device to second by 2 outputs, second non-zero values 2 are regard as local address from equipment, and will be defeated after non-zero values 2 plus one
Out from the device to third, and so on, the non-zero values that n-th is received from equipment are N, therefore, sheet of the n-th from equipment
Way address is N.When it is implemented, local address is indicated with 16 system numbers.
Further, the present invention carries out the reading from the determination of equipment and data or is write in such a way that device address addresses
Enter.As shown in Fig. 2, main equipment from it is described from equipment read data or to from equipment be written data when, main equipment generate comprising ground
The instruction of location information and data information is sent to from the device.Topological structure as shown in Figure 2 is write from memory by the way of being connected in series
In the case of recognizing, it is in bypass (Bypass) state from equipment, within a clock cycle, all can receive from equipment to master sets
Whether the instruction that preparation is sent matches from the address information in equipment decision instruction with local address, if mismatching, continues to parse
Data information in instruction, and continue to keep bypass condition.When judging that address information and local address match from equipment, from
Equipment is not continuing to keep bypass condition, and the reading or write-in of data should be carried out from equipment.
Further, it each can also individually be communicated from equipment with an ancillary equipment, at this point, each from equipment as master
SPI bridge between equipment and ancillary equipment.It, should be from equipment not to receiving when a certain SPI bridge function from equipment is non-enabled
Address information and local information carry out matching treatment, the address information is directly sent to next stage from the device.
When it is implemented, main equipment can enable a certain SPI bridge function from equipment by such as issuing orders:
0xA5- > local address- > open time, wherein local address is SPI bridge function to be opened
From equipment local address;Open time is the opening time, wherein the opening time is calculated with byte.When local address is 0
When, enable all SPI bridge functions from equipment.When enabled from the SPI bridge function of equipment, main equipment can be connected with this from equipment
Ancillary equipment carry out data interaction.
Technology contents and technical characteristic of the invention have revealed that as above, however those skilled in the art still may base
Make various replacements and modification without departing substantially from spirit of that invention, therefore, the scope of the present invention in teachings of the present invention and announcement
It should be not limited to the revealed content of embodiment, and should include various without departing substantially from replacement and modification of the invention, and be this patent Shen
Please claim covered.