Communication system and communication method based on SPI bus and storage medium
The SPI bus communication system optimizes address allocation by sequentially assigning addresses to slaves, reducing the need for additional slave select lines and enhancing accuracy, thus conserving host port resources.
Patent Information
- Application Number
- CN202310642367.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-01
- Publication Date
- 2024-12-03
AI Technical Summary
The existing SPI bus communication system requires multiple slave select lines for each additional slave, leading to significant waste of port resources on the host when connecting multiple slaves.
A communication system where the host sends initialization signals to slaves in sequence, allowing each slave to set a new address in response to an address reset signal, eliminating the need for additional slave select lines and improving address allocation accuracy.
This approach conserves host port resources and enhances address allocation precision by assigning addresses sequentially without requiring additional slave select lines.
Smart Images

Figure CN119066009A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of communication technology, and in particular to a communication system, a communication method and a storage medium based on an SPI bus. Background Art
[0002] SPI (serial peripheral interface) bus technology is a high-speed, synchronous, full-duplex communication bus technology. SPI is a serial peripheral interface. It is a high-speed, full-duplex communication serial bus interface with the advantages of simple communication and fast data transmission rate.
[0003] SPI works in master-slave mode. The SPI master device (spimaster, referred to as the host) provides the clock signal for SPI communication and is the active party of communication. All communications are initiated by the host, which can initiate or stop communication at any time; the SPI slave device (spisalve, referred to as the slave) is the passive party of the SPI communication process, and the sending and receiving process is generally controlled by the SPI master device. The master-slave mode usually includes a host and one or more slaves, requiring at least 4 lines, namely the serial clock line (SCLK), host output / slave input (MOSI), host input / slave output (MISO), and slave select line (NSS). The host communicates with different slaves by selecting different NSS lines. Only the slave whose NSS line is selected by the host can respond to the host.
[0004] However, the host needs to be connected to each slave with a separate NSS line, that is, each additional slave needs to add an additional NSS line. When the host mounts multiple slaves, the host needs to be equipped with multiple ports to connect multiple NSS lines, which greatly wastes the port resources on the host. Summary of the invention
[0005] The embodiments of the present application provide a communication system, a communication method and a storage medium based on an SPI bus, which can effectively avoid wasting port resources on a host.
[0006] The communication system comprises: a host and a plurality of slaves;
[0007] The host is provided with an initialization signal output terminal, the multiple slaves include a final-stage slave and at least one intermediate-stage slave, the intermediate-stage slave is provided with an initialization signal input terminal and an initialization signal output terminal, the final-stage slave is provided with an initialization signal input terminal, the host and the multiple slaves are connected in sequence by connecting the initialization signal output terminal with the initialization signal input terminal, the host is a first-stage communication device therein, and the final-stage slave is a final-stage communication device therein;
[0008] The host is used to send a first initialization signal to a next-level communication device through the initialization signal output terminal after the slave enters the initialization state;
[0009] The intermediate-level slave is used to exit the initialization state upon receiving the first initialization signal, to set a new address in response to the address reset signal sent by the host and matching the initialization address, and to send the first initialization signal to the next-level slave through the initialization signal output terminal; the final-level slave is used to exit the initialization state upon receiving the first initialization signal, to set a new address in response to the address reset signal sent by the host and matching the initialization address; wherein the new addresses of the slaves are different from each other;
[0010] The host is also used to perform addressing communication with the slave according to the new address set by the slave.
[0011] Furthermore, the host is used to send the address reset signal to the slaves at a preset interval, so that each of the slaves sets a new address in response to the address reset signal.
[0012] Furthermore, the address reset signal includes an address to be allocated, and the multiple addresses to be allocated of the multiple address reset signals are arranged in ascending order according to the time sequence of sending the address reset signals.
[0013] Furthermore, the slave is used to receive a communication signal sent by the host, and if a target address in the communication signal matches an address of the slave, feed back a response signal to the host, wherein the communication signal includes the address reset signal.
[0014] Furthermore, the host is used to send the address reset signal to the slave once when receiving the response signal fed back by the slave.
[0015] Furthermore, the intermediate-level slave is used to enter the initialization state upon receiving the second initialization signal sent by the host and send the second initialization signal to the next-level slave through the initialization signal output terminal; the final-level slave is used to enter the initialization state upon receiving the second initialization signal.
[0016] Furthermore, the host is used to send an initialization communication signal to each of the slaves to control each of the slaves to enter an initialization state.
[0017] Furthermore, the communication signal sent by the host includes: a target address segment, a device status control segment, a data object segment, a data length segment and a data segment; wherein the target address segment represents the address of the slave to be accessed, the device status control segment is used to control the device status of the slave, the data object segment represents the data object of the slave to be accessed, the data segment represents the data to be written to the slave, and the data length segment represents the length of the data to be written or read from the slave.
[0018] Furthermore, the communication signal sent by the host also includes: a check byte segment, and the check byte segment is used to check the data to be written into the slave.
[0019] Furthermore, the communication signal sent by the slave to the host includes: a slave address segment, a device status segment, a data object segment, a data length segment and a data segment; wherein the slave address segment represents the address of the slave, the device status segment represents the device status information of the slave and the fault status information of the slave, the data object segment represents the data object of the host to be accessed, the data segment represents the data to be written to the host, and the data length segment represents the length of the data to be written or read from the host.
[0020] The embodiment of the present application also provides a communication method based on SPI bus, which is applied to a communication system, wherein the communication system includes: a host and multiple slaves, wherein the host is provided with an initialization signal output terminal, wherein the multiple slaves include a final-stage slave and at least one intermediate-stage slave, wherein the intermediate-stage slave is provided with an initialization signal input terminal and an initialization signal output terminal, wherein the final-stage slave is provided with an initialization signal input terminal, wherein the host and the multiple slaves are connected in sequence by connecting the initialization signal output terminal with the initialization signal input terminal, wherein the host is a first-stage communication device, and wherein the final-stage slave is a final-stage communication device; wherein the method includes:
[0021] After the slave enters the initialization state, the initialization signal output terminal of the host sends a first initialization signal to the next level communication device;
[0022] Each of the intermediate-level slaves exits the initialization state upon receiving the first initialization signal, sets a new address in response to an address reset signal sent by the host that matches the initialization address and sends the first initialization signal to the next-level slave through the initialization signal output terminal;
[0023] The final slave exits the initialization state upon receiving the first initialization signal, and sets a new address in response to an address reset signal sent by the host that matches the initialization address; wherein the new addresses of the slaves are different from each other;
[0024] The host performs addressing communication with the slave according to the new address that has been set by the slave.
[0025] The embodiment of the present application further provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed on a computer, the computer executes the above method.
[0026] The beneficial effects of the SPI bus-based communication system provided by the embodiment of the present application are that, on the one hand, by first allocating an address to the slave and then achieving communication through host addressing, there is no need to add a slave selection line for each additional slave, thereby effectively avoiding the waste of port resources on the host; on the other hand, by controlling the initialization signal output end to send the first initialization signal to the next-level slave one by one, controlling the next-level slave to respond to the address reset signal sent by the host, and setting new addresses for the slaves one by one, the accuracy of address allocation is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0028] Figure 1 A schematic diagram of a communication system based on an SPI bus disclosed in an embodiment of the present application;
[0029] Figure 2 A schematic diagram of a communication signal transmitted in a communication system disclosed in an embodiment of the present application;
[0030] Figure 3 A schematic diagram of a broadcast communication signal disclosed in an embodiment of the present application;
[0031] Figure 4 A schematic diagram of switching a device state disclosed in an embodiment of the present application;
[0032] Figure 5 A flow chart of a communication method disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0033] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0034] In the description of the embodiments of the present application, it should be noted that the terms "center", "up", "down", "left", "right", "vertical", "horizontal", "inside", "outside", etc. indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings. They are only for the convenience of describing the embodiments of the present application and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation. Therefore, they cannot be understood as limitations on the embodiments of the present application.
[0035] In the description of the embodiments of the present application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the embodiments of the present application can be understood according to specific circumstances.
[0036] The existing master-slave communication mode of the SPI bus usually includes a host and one or more slaves, and requires at least four lines, namely a serial clock line (SCLK), a host output / slave input (MOSI), a host input / slave output (MISO), and a slave select line (NSS). The host communicates with different slaves by selecting different slave select lines, and only the slaves whose slave select lines are selected by the host can respond to the host. However, the host needs to connect a separate slave select line to each slave, that is, one more slave select line needs to be added for each additional slave. When the host mounts multiple slaves, the host needs to be equipped with multiple ports to connect the multiple slave select lines, which greatly wastes the port resources on the host. Therefore, an embodiment of the present application provides a communication system based on the SPI bus, which can effectively avoid the waste of port resources on the host. The communication system is as follows: Figure 1 As shown, the details are as follows:
[0037] The communication system of the embodiment of the present application includes: a host and multiple slaves, and the communication lines between the host and the slaves include: a serial clock line (SCLK), a host output / slave input (MOSI), a host input / slave output (MISO) and a slave select line (NSS), wherein the host and the multiple slaves are connected through the same slave select line, the slave select line is used to transmit the SPI chip select signal, and can be set to be valid at a low level, that is, the falling edge indicates that data transmission is ready to start, and the rising edge indicates that the data transmission is completed; the serial clock line is used to transmit the SPI clock signal, and can be set to a low level when idle, that is, the rising edge updates the output and the falling edge samples the data; the clock phase of the SPI timing can be set to 1, that is, data is sampled at the second edge of the SCLK clock; the clock polarity is 0, that is, the SCLK clock is at a low level when idle; when the MOSI line and the MISO line transmit communication signals, the corresponding byte data transmission is transmitted with the high bit first and the low bit last. The host and slave communicate by addressing, that is, communicating by accessing the slave address. Each slave has an independent device address. The host can add the slave address to the communication signal sent to specify the receiving slave of this frame communication signal. The slave adds the local address to the feedback communication signal to indicate the sender of this frame feedback communication signal.
[0038] In the embodiment of the present application, the host is provided with an initialization signal output terminal (INITD), the plurality of slaves include a final-stage slave and at least one intermediate-stage slave, the intermediate-stage slave is provided with an initialization signal input terminal (INIT) and an initialization signal output terminal (INITD), the final-stage slave is provided with an initialization signal input terminal (INIT), the host and the plurality of slaves are connected in sequence by connecting the initialization signal output terminal (INITD) with the initialization signal input terminal (INIT), the host is the first-stage communication device, the final-stage slave is the final-stage communication device, and the first-stage communication device located after the host is called the first intermediate-stage slave. It can be understood that the initialization signal output terminal (INITD) of the host is connected to the initialization signal input terminal (INIT) of the first intermediate-stage slave (slave 1), the initialization signal output terminal (INITD) of the first intermediate-stage slave is connected to the initialization signal input terminal (INIT) of the next-stage slave (slave 2), and each slave is connected in this order.
[0039] The host is used to send a first initialization signal to the next-level communication device through the initialization signal output terminal after the slave enters the initialization state, wherein the next-level communication device corresponding to the host is the first intermediate-level slave, and the host can send the first initialization signal to the first intermediate-level slave through the initialization signal output terminal to control the first intermediate-level slave to exit the initialization state; it can be understood that the address of the slave when it is in the initialization state is the initialization address, and the initialization address can be set to 0, and after entering the initialization state, the slave does not respond to the communication signal sent by the host, and the communication signal includes an address reset signal; the initialization signal output terminal of the host sends the first initialization signal to the initialization signal input terminal of the first intermediate-level slave entering the initialization state, and controls the first intermediate-level slave to exit the initialization state. Although the address of each slave is the initialization address at this time, only the first intermediate level that exits the initialization state can respond to the address reset signal and set a new address. In the embodiment of the present application, the initialization signal output terminal of the host sends the first initialization signal to control the first intermediate-level slave to exit the initialization state, so that the first intermediate-level slave responds to the address reset signal sent by the host that matches the initialization address to set a new address and exit the initialization state. It can be understood that when the first intermediate-level slave exits the initialization state, the first intermediate-level slave can respond to an address reset signal sent by the host that matches the initialization address, and the address reset signal includes the address to be assigned. When the first intermediate-level slave responds to the address reset signal, the address to be assigned is set as the new address of the first intermediate-level slave.
[0040] Among them, the intermediate-level slave is used to exit the initialization state upon receiving the first initialization signal, so as to respond to the address reset signal sent by the host and matching the initialization address to set a new address and send the first initialization signal to the next-level slave through the initialization signal output terminal; it can be understood that when the intermediate-level slave responds to the address reset signal sent by the host, the initialization signal output terminal of the intermediate-level slave outputs the first initialization signal to the next-level slave. That is, when the first intermediate-level slave responds to the address reset signal sent by the host, the initialization signal output terminal of the first intermediate-level slave outputs the first initialization signal to the initialization signal input terminal of the next-level slave in the initialization state, and controls the next-level slave to exit the initialization state, so that the next-level slave responds to the address reset signal sent by the host and matching the initialization address to set a new address and send the first initialization signal, so as to make the next-level slave exit the initialization state one by one and set a new address for the next-level slave, until all intermediate-level slaves are set with new addresses.
[0041] The final slave is used to exit the initialization state upon receiving the first initialization signal, and to set a new address in response to an address reset signal sent by the host that matches the initialization address. It can be understood that when the upper-level slave corresponding to the final slave responds to the address reset signal to set a new address, the initialization signal output end of the upper-level slave will send the first initialization signal to the initialization signal input end of the final slave, and the initialization signal input end of the final slave exits the initialization state upon receiving the first initialization signal, and responds to the address reset signal sent by the host to set a new address. Among them, the new addresses of the slaves are different from each other, that is, when the host sends an address reset signal to the slave, the address to be assigned in the address reset signal sent each time is different, so as to set a different new address for each slave.
[0042] In an implementable manner, the first initialization signal can be set to a high level, that is, when the initialization signal input terminal of the slave receives a high level, the slave exits the initialization state; when the slave exits the initialization state, it responds to the address reset signal sent by the host that matches the initialization address, and the initialization signal output terminal of the slave sends a high level to the initialization signal input terminal of the next-level slave, and when the slave enters the initialization state, the initialization signal output terminal of the slave outputs a low level. That is, the slave address allocation process can be that the initialization signal output terminal of the host sends a high level signal to the initialization signal input terminal of the first intermediate-level slave, the first intermediate-level slave exits the initialization state, and the initialization signal output terminal of the first intermediate-level slave keeps outputting a low level signal, that is, the next-level slave is still in the initialization state, at this time, the address reset signal accesses the first intermediate-level slave through the initialization address, and the first intermediate-level slave responds to the address reset signal to set a new address. When the first intermediate-level slave responds to the address reset signal to set a new address, the initialization signal output terminal of the first intermediate-level slave outputs a high-level signal to the initialization signal input terminal of the next-level slave, so that the next-level slave exits the initialization state, and the next-level slave responds to the address reset signal to set a new address, and sets new addresses for the next-level slaves in turn. When the new addresses of all slaves are set, the host performs addressing communication with the slave according to the new address that has been set for the slave. It is understandable that the allocated new address can be recorded in the host, and the host can use the new address as the addressing address in the communication signal sent to perform addressing communication with the slave.
[0043] It can be seen that the beneficial effects of the SPI bus-based communication system provided by the embodiment of the present application are that, on the one hand, by first assigning an address to the slave and then achieving communication through host addressing, there is no need to add a slave selection line for each additional slave, thereby effectively avoiding the waste of port resources on the host; on the other hand, by controlling the initialization signal output end one by one to send the first initialization signal to the next-level slave, controlling the next-level slave to respond to the address reset signal sent by the host, and setting new addresses for the slaves one by one, the accuracy of address allocation is improved.
[0044] Further, the slave needs a certain response time from receiving the first initialization signal to exiting the initialization state. In order to give the slave enough response time to respond to the address reset signal, that is, when the host sends the address reset signal to the slave, the slave has already exited the initialization state. When the host assigns an address to the slave, the address reset signal is sent to the slave at a preset interval time, so that each slave responds to the address reset signal to set a new address. Among them, the length of each interval in the preset interval time can be the same or different, which is not specifically limited here; the interval length can be 5 seconds or 8 seconds, which is not specifically limited here. Among them, the address reset signal includes the address to be assigned, that is, the slave responds to the address reset signal after exiting the initialization state, and sets the address to be assigned in the address reset signal as the new address of the slave; and the multiple addresses to be assigned of the multiple address reset signals are set in order from small to large according to the time sequence of sending the address reset signal, that is, the new address of the slave is sorted from small to large according to the time sequence of the slave exiting the initialization state, that is, the new address of the first intermediate slave is the smallest, and the new address of the last slave is the largest. It can be understood that there is a difference between the address to be assigned and the initialization address.
[0045] Further, the slave is used to receive the communication signal sent by the host. If the target address in the communication signal matches the address of the slave, a response signal is fed back to the host, wherein the communication signal includes an address reset signal. An ACK signal line (ACK) can be set between the host and each slave to implement a response mechanism. When the addressing address in the communication signal received by the slave is the address of the slave, the host is responded to through the ACK signal line to confirm that the slave has received the communication signal. Among them, the slave can set the ACK port corresponding to the ACK signal line to a high level before starting to receive the communication signal or when receiving the communication signal. When the slave checks that the device address indicated by the received communication signal is the local address, the ACK port is set to a low level to inform the host that the communication signal has been received. When the host assigns an address to a slave, in order to ensure the accuracy of the address assignment, it can first send a communication signal to the slave, and when receiving the response signal fed back by the slave, it can then send an address reset signal to the slave to assign an address to each slave; that is, it can first send a communication signal with the addressing address as the initialization address to ensure that there is a slave that has exited the initialization state, and the slave that has exited the initialization state can respond to the communication signal and feed back a response signal to the host; the host then sends an address reset signal to the slave to assign an address to the next slave.
[0046] Further, the intermediate-level slave is used to enter the initialization state when receiving the second initialization signal sent by the host and send the second initialization signal to the next-level slave through the initialization signal output terminal; the final-level slave is used to enter the initialization state when receiving the second initialization signal. Among them, each slave can be controlled to enter the initialization state through the initialization signal output terminal of the host. Specifically, the initialization signal output terminal of the host is also used to send the second initialization signal to the initialization signal input terminal of the first intermediate-level slave to control the first intermediate-level slave to enter the initialization state, so that the initialization signal output terminal of the first intermediate-level slave sends the second initialization signal to the next-level slave, and controls the next-level slave to enter the initialization state until the final-level slave enters the initialization state. It can be understood that when the initialization signal input terminal of the slave receives the second initialization signal, the slave enters the initialization state, and when the slave enters the initialization state, the initialization signal output terminal of the slave will send the second initialization signal to the initialization signal input terminal of the next-level slave. In one implementable manner, the second initialization signal can be a low-level signal, that is, the initialization signal output terminal of the host can send a low-level signal to the initialization signal input terminal of the first intermediate-level slave, the first intermediate-level slave enters the initialization state, and the slave address is the initialization address; after the first intermediate-level slave enters the initialization state, the initialization signal output terminal of the first intermediate-level slave outputs a low-level signal to the next-level slave until each slave enters the initialization state.
[0047] Furthermore, each slave can be controlled to enter the initialization state by sending a communication signal to the slave; specifically, the host is used to send an initialization communication signal to each slave to control each slave to enter the initialization state. It is understandable that the communication signal sent by the host to the slave may include a device state control segment (control) to control the slave to enter the corresponding device state, and the device state includes an initialization state, a ready state, a stop state and a running state to implement a management mechanism for establishing communication, maintaining communication and releasing communication. It is understandable that the address reset signal includes a device state control segment (control), and the device state corresponding to the device state control segment (control) of the address reset signal is the ready state. Figure 4As shown, 0, 5, 6, and 7 indicate that the slave receives an initialization communication signal or a power-on reset signal, and the slave address is the initialization address at this time; 1 indicates that the slave receives an address reset signal, and the slave address is a new address instead of an initialization address; 2 and 3 indicate that the slave receives a stop communication signal, and the slave can receive module configuration data at this time; 4 indicates that the slave receives a run communication signal, and the slave and the host can interact with process data at this time. It can be understood that when the slave is in the initialization state or the reset state, the initialization signal output terminal of the slave outputs the initialization signal, and when the slave is in the non-initialization state and the non-reset state, such as the ready state, the stop state, and the running state, the initialization signal output terminal of the slave outputs the first initialization signal to control the next-level slave to exit the initialization state.
[0048] In the embodiment of the present application, the communication signal (MOSI) sent by the host is as follows: Figure 2 As shown, it includes: a target address segment (ID), a device status control segment (Control), a data object segment (Index), a data length segment (Length) and a data segment (Data); wherein the target address segment indicates the address of the slave to be accessed, that is, when the host sends a communication signal, the address in the target address segment is used to find the slave matching the address, and the communication signal is sent to the matching slave. The size of the target address segment can be set to 1 byte; the device status control segment is used to control the device status of the slave, and the size can be set to 1 byte. The data content of bits 0 to 3 of the byte can be used to indicate that the slave is controlled to enter the initialization state, the ready state, the stop state and the running state respectively, and bits 4 to 7 are reserved; the data object segment indicates the data object of the slave to be accessed, and the size can be set to 2 bytes; the data segment indicates the data to be written to the slave. If the data object to be accessed is read-only, the slave does not write the received data into the corresponding data object. The size is generally fixed to 16 bytes. If the valid data is less than 16 bytes, 0xC3 can be used for padding; the data length segment indicates the length of the data to be written or read from the slave, and the size is 1 byte. The communication signal sent by the host also includes a check byte segment (Check), which is used to check the data to be written into the slave. The check code of the check byte segment can be a longitudinal redundancy check code or a cyclic redundancy check code, which is used to check whether the communication is correct, and the specific details are not limited here.
[0049] Further, as one of the embodiments, the communication signal (MISO) sent by the slave to the host includes: a slave address segment (ID), a device status segment (Status), a data object segment (Index), a data length segment (Length) and a data segment (Data). Among them, the slave address segment indicates the address of the slave, that is, it indicates which slave the communication signal (MISO) originates from; the device status segment indicates the device status of the slave and the fault status of the slave. It can be understood that in the communication signal sent by the slave, the device status content of the device status segment is the same as the content of the device status control segment of the communication signal sent by the host. The data object segment indicates the data object of the host to be accessed, the data segment indicates the data to be written to the host, and the data length segment indicates the length of the data to be written or read from the host.
[0050] The data object segment has a corresponding data object index, and the data object index is shown in Table 1:
[0051] Table 1. Data object definition
[0052]
[0053]
[0054] In the table, for the slave, the node ID represents the slave address. When the host assigns an address to the slave, the target address segment (ID) in the address reset signal sent by the host is set to the initialization address, and the address to be assigned is the content of the data segment (Data) in the address reset signal, and the assignable address range is 1 to 254, that is, the assignable address range in the address reset signal is 1 to 254. Address 0 represents the slave address in the initialization state (that is, the initialization address); 255 is the broadcast address, such as Figure 3 As shown, when the target address segment (ID) of the communication signal sent by the host is 255 (0xFF), it is a broadcast signal. After receiving the broadcast signal, the slave does not need to send a response signal to the host.
[0055] The device status indicates the device status of the slave. The device status is shown in Table 2:
[0056] Table 2. Equipment status
[0057] coding state 0x00 initialization 0x01 Ready 0x02 stop 0x03 run 0xff Reset, system restart, for firmware upgrade
[0058] It can be understood that the address where the device status control segment content in the communication signal sent by the host is written is the address corresponding to the device status in the data object index, and the address where the data segment content is written is the address specified according to the data object segment content.
[0059] The data object index of the data object segment in the communication signal sent by the slave also includes a fault status flag, as shown in Table 3:
[0060] Table 3. Fault status signs
[0061] coding Fault 0x00 No trouble 0x01 There is a fault. For detailed fault information, see 0x00E0-0x00FF
[0062] It is understandable that the content of the device status segment (Status) in the communication signal sent from the slave to the host includes: the content of the device status (0x0001) and the fault status flag (0x0002) in the data object index, and the slave can write the device status and fault status of the slave in the communication signal sent to the host. As one of the embodiments, the content of the device status segment is 1 byte, in which the 0-6 bits of data are used to represent the device status, and the 7th bit of data is used to represent the fault status flag.
[0063] The present application also provides a communication method based on the SPI bus. Figure 5 As shown, it specifically includes steps 501 to 504.
[0064] 501. Control a slave of the communication system to enter an initialization state.
[0065] The communication method of the embodiment of the present application is applied to a communication system, and the communication system includes: a host and multiple slaves, the host is provided with an initialization signal output terminal, the multiple slaves include a final-level slave and at least one intermediate-level slave, the intermediate-level slave is provided with an initialization signal input terminal and an initialization signal output terminal, the final-level slave is provided with an initialization signal input terminal, the host and the multiple slaves are connected in sequence by connecting the initialization signal output terminal with the initialization signal input terminal, the host is the first-level communication device, the final-level slave is the final-level communication device, and the first intermediate-level slave located after the host is the first intermediate-level slave. In the embodiment of the present application, the slaves of the communication system can be controlled to enter the initialization state, specifically, each slave can be controlled to enter the initialization state by sending an initialization communication signal to the slave or outputting a second initialization signal through the initialization signal output terminal of the host, and the specific details are not limited here.
[0066] 502. The initialization signal output terminal of the host sends a first initialization signal to the next-level communication device.
[0067] When the slave enters the initialization state, the initialization signal output terminal of the host sends a first initialization signal to the next-level communication device, wherein the next-level communication device corresponding to the host is the first intermediate-level slave, that is, the first initialization signal is sent to the first intermediate-level slave to control the first intermediate-level slave to exit the initialization state, so that the first intermediate-level slave responds to the address reset signal sent by the host that matches the initialization address to set a new address. It can be understood that when the slave enters the initialization state, the slave does not respond to the communication signal sent by the host, and when the slave exits the initialization state, the slave responds to the address reset signal sent by the host, and uses the address to be assigned in the address reset signal as the new address of the slave.
[0068] 503. Each intermediate-level slave exits the initialization state upon receiving the first initialization signal, sets a new address in response to the address reset signal sent by the host, and sends the first initialization signal to the slave at the next level.
[0069] Each intermediate-level slave exits the initialization state upon receiving the first initialization signal, responds to the address reset signal sent by the host to set a new address, and sends the first initialization signal to the next-level slave. It is understandable that after each intermediate-level slave exits the initialization state, the corresponding slave address is still the initialization address, and can respond to the address reset signal sent by the host that matches the initialization address to set a new address. When the first intermediate-level slave responds to the address reset signal, it sends the first initialization signal to the next-level slave through the initialization signal output terminal, controls the next-level slave in the initialization state to exit the initialization state, so that the next-level slave responds to the address reset signal sent by the host that matches the initialization address to set a new address and send the first initialization signal, so that the next-level slave exits the initialization state one by one and sets a new address for the next-level slave, until all intermediate-level slaves are set with new addresses.
[0070] 504. The final slave exits the initialization state upon receiving the first initialization signal, and responds to the address reset signal sent by the host to set a new address, wherein the new addresses of the slaves are different from each other.
[0071] The final slave exits the initialization state upon receiving the first initialization signal, and responds to the address reset signal sent by the host to set a new address. When the upper-level slave corresponding to the final slave responds to the address reset signal to set a new address, the initialization signal output end of the upper-level slave sends the first initialization signal to the initialization signal input end of the final slave. The initialization signal input end of the final slave exits the initialization state upon receiving the first initialization signal, and responds to the address reset signal sent by the host to set a new address. At this time, each slave is set with a new address, and the new addresses of the slaves are different from each other.
[0072] 505. Perform addressing communication with the slave according to the new address set by the slave.
[0073] After all slaves have set new addresses, the master can communicate with the slaves according to the new addresses that have been set.
[0074] The beneficial effects of the communication method based on the SPI bus provided in the embodiment of the present application are that, on the one hand, by first assigning an address to the slave and then achieving communication through host addressing, there is no need to add a slave selection line for each additional slave, thereby effectively avoiding the waste of port resources on the host; on the other hand, by controlling the initialization signal output end to send the first initialization signal to the next-level slave one by one, controlling the next-level slave to respond to the address reset signal sent by the host, and setting new addresses for the slaves one by one, the accuracy of address allocation is improved.
[0075] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0076] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0077] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0078] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0079] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. A communication system based on an SPI bus, wherein the communication device of the communication system comprises: A master and multiple slaves, characterized by: The host is provided with an initialization signal output terminal, the multiple slaves include a final-stage slave and at least one intermediate-stage slave, the intermediate-stage slave is provided with an initialization signal input terminal and an initialization signal output terminal, the final-stage slave is provided with an initialization signal input terminal, the host and the multiple slaves are connected in sequence by connecting the initialization signal output terminal with the initialization signal input terminal, the host is a first-stage communication device therein, and the final-stage slave is a final-stage communication device therein; The host is used to send a first initialization signal to a next-level communication device through the initialization signal output terminal after the slave enters the initialization state; The intermediate-level slave is used to exit the initialization state upon receiving the first initialization signal, to set a new address in response to the address reset signal sent by the host and matching the initialization address, and to send the first initialization signal to the next-level slave through the initialization signal output terminal; the final-level slave is used to exit the initialization state upon receiving the first initialization signal, to set a new address in response to the address reset signal sent by the host and matching the initialization address; wherein the new addresses of the slaves are different from each other; The host is also used to perform addressing communication with the slave according to the new address set by the slave.
2. The communication system according to claim 1, characterized in that The host is used for sending the address reset signal to the slaves at a preset interval, so that each of the slaves sets a new address in response to the address reset signal.
3. The communication system according to claim 2, characterized in that The address reset signal includes an address to be allocated, and the multiple addresses to be allocated of the multiple address reset signals are arranged in ascending order according to the time sequence of sending the address reset signals.
4. The communication system according to claim 1, characterized in that: The slave is used to receive the communication signal sent by the host, and if the target address in the communication signal matches the address of the slave, then feed back a response signal to the host, wherein the communication signal includes the address reset signal.
5. The communication system according to claim 4, characterized in that: The host is used to send the address reset signal to the slave once when receiving the response signal fed back by the slave.
6. The communication system according to claim 1, characterized in that: The intermediate-level slave is used to enter the initialization state upon receiving the second initialization signal sent by the host and send the second initialization signal to the next-level slave through the initialization signal output terminal; the final-level slave is used to enter the initialization state upon receiving the second initialization signal.
7. The communication system according to claim 1, characterized in that: The host is used to send an initialization communication signal to each of the slaves to control each of the slaves to enter an initialization state.
8. The communication system according to any one of claims 1 to 7, characterized in that: The communication signal sent by the host includes: a target address segment, a device status control segment, a data object segment, a data length segment and a data segment; wherein the target address segment represents the address of the slave to be accessed, the device status control segment is used to control the device status of the slave, the data object segment represents the data object of the slave to be accessed, the data segment represents the data to be written to the slave, and the data length segment represents the length of the data to be written or read from the slave.
9. The communication system according to claim 8, characterized in that: The communication signal sent by the host also includes: a check byte segment, and the check byte segment is used to check the data to be written into the slave.
10. The communication system according to any one of claims 1 to 7, characterized in that: The communication signal sent by the slave to the host includes: a slave address segment, a device status segment, a data object segment, a data length segment and a data segment; wherein the slave address segment represents the address of the slave, the device status segment represents the device status information of the slave and the fault status information of the slave, the data object segment represents the data object of the host to be accessed, the data segment represents the data to be written to the host, and the data length segment represents the length of the data to be written or read from the host.
11. A communication method based on SPI bus, applied to a communication system, the communication system comprising: A host and a plurality of slaves, wherein the host is provided with an initialization signal output terminal, the plurality of slaves include a final-stage slave and at least one intermediate-stage slave, the intermediate-stage slave is provided with an initialization signal input terminal and an initialization signal output terminal, the final-stage slave is provided with an initialization signal input terminal, the host and the plurality of slaves are connected in sequence by connecting the initialization signal output terminal with the initialization signal input terminal, the host is a first-stage communication device therein, and the final-stage slave is a final-stage communication device therein; characterized in that the method comprises: After the slave enters the initialization state, the initialization signal output terminal of the host sends a first initialization signal to the next level communication device; Each of the intermediate-level slaves exits the initialization state upon receiving the first initialization signal, sets a new address in response to an address reset signal sent by the host that matches the initialization address and sends the first initialization signal to the next-level slave through the initialization signal output terminal; The final slave exits the initialization state upon receiving the first initialization signal, and sets a new address in response to an address reset signal sent by the host that matches the initialization address; wherein the new addresses of the slaves are different from each other; The host performs addressing communication with the slave according to the new address that has been set by the slave.
12. A computer-readable storage medium storing computer-executable instructions, characterized in that: The computer executable instructions are used to make the computer perform the method according to claim 11 when being executed on a computer.
