[go: up one dir, main page]

CN115061961A - A kind of communication method and device based on SPI - Google Patents

A kind of communication method and device based on SPI Download PDF

Info

Publication number
CN115061961A
CN115061961A CN202210755414.XA CN202210755414A CN115061961A CN 115061961 A CN115061961 A CN 115061961A CN 202210755414 A CN202210755414 A CN 202210755414A CN 115061961 A CN115061961 A CN 115061961A
Authority
CN
China
Prior art keywords
slave
information
authentication information
command
spi
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.)
Pending
Application number
CN202210755414.XA
Other languages
Chinese (zh)
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.)
Xian Yep Telecommunication Technology Co Ltd
Original Assignee
Xian Yep Telecommunication Technology Co Ltd
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 Xian Yep Telecommunication Technology Co Ltd filed Critical Xian Yep Telecommunication Technology Co Ltd
Priority to CN202210755414.XA priority Critical patent/CN115061961A/en
Publication of CN115061961A publication Critical patent/CN115061961A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/14Handling requests for interconnection or transfer
    • G06F13/36Handling requests for interconnection or transfer for access to common bus or bus system
    • G06F13/362Handling requests for interconnection or transfer for access to common bus or bus system with centralised access control
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Small-Scale Networks (AREA)

Abstract

The invention discloses a communication method and a device based on SPI, wherein the communication method is suitable for a master device and a plurality of slave devices which are connected through an SPI bus, and comprises the following steps: the method comprises the steps that a master device sends command information to a plurality of slave devices, wherein the command information comprises preset authentication information; the slave devices acquire command information and perform matching according to the authentication information; and the slave device successfully matched with the authentication information executes the corresponding command. The invention determines the slave device responding to the master device through the matching of the plurality of slave devices to the authentication information respectively, thereby realizing the selection control and information exchange of the master device to the plurality of slave devices and being beneficial to saving GPIO port resources of the master device.

Description

一种基于SPI的通信方法与装置A kind of communication method and device based on SPI

技术领域technical field

本发明涉及设备通信技术领域,具体涉及一种基于SPI的通信方法与装置。The present invention relates to the technical field of device communication, in particular to an SPI-based communication method and device.

背景技术Background technique

SPI是串行外设接口(Serial Peripheral Interface)的缩写,它是一种种高速的,全双工,同步的通信总线,通过它可以实现主设备与从设备之间的通信,以及主设备对从设备的控制,SPI总线总共包括数据传输线、时钟信号线和片选信号线,而数据传输线可以包括主设备数据输入线和主设备数据输出线,其中,片选信号线用于传输主设备控制从设备的控制信号,只有在传输的片选信号为预先设定的使能信号时,主设备才能对从设备进行有效操作。SPI is the abbreviation of Serial Peripheral Interface (Serial Peripheral Interface), it is a kind of high-speed, full-duplex, synchronous communication bus, through which the communication between the master device and the slave device, and the master device to the slave device can be realized. For the control of the device, the SPI bus includes a data transmission line, a clock signal line and a chip select signal line, and the data transmission line can include a master device data input line and a master device data output line, wherein the chip select signal line is used to transmit the master device control slave The control signal of the device, only when the transmitted chip select signal is a preset enable signal, the master device can effectively operate the slave device.

目前,由于系统架构的复杂度越来越高,主设备所需要通信的从设备也就越来越多,当主设备与其它从设备通过SPI协议进行通信且需要控制多个从设备时,主设备需要通过多个片选端口去与对应的从设备连接,这意味着需要占用主设备大量的GPIO口资源,而一些只有单个片选信号的主设备甚至无法实现控制多个从设备的功能。At present, due to the increasing complexity of the system architecture, the master device needs to communicate with more and more slave devices. When the master device communicates with other slave devices through the SPI protocol and needs to control multiple slave devices, the master device needs to communicate with more and more slave devices. It is necessary to connect to the corresponding slave device through multiple chip select ports, which means that a large number of GPIO port resources of the master device are occupied, and some master devices with only a single chip select signal cannot even realize the function of controlling multiple slave devices.

因此,有必要提供一种新的基于SPI的通信方法与装置,以解决上述问题。Therefore, it is necessary to provide a new SPI-based communication method and device to solve the above problems.

发明内容SUMMARY OF THE INVENTION

本发明的目的在于提供一种基于SPI的通信方法、装置、电子设备和计算机可读存储介质,能够在不占用过多GPIO口资源的情况下,实现主设备对多个从设备的选用控制以及信息交流。The purpose of the present invention is to provide a communication method, device, electronic device and computer-readable storage medium based on SPI, which can realize the selection control of multiple slave devices by the master device without occupying too many GPIO port resources and information exchange.

为实现上述目的,本发明提供了一种基于SPI的通信方法方法,适用于通过SPI总线连接的主设备与多个从设备,包括:In order to achieve the above object, the present invention provides a communication method based on SPI, which is applicable to the master device and multiple slave devices connected by the SPI bus, including:

所述主设备向多个所述从设备发送命令信息,所述命令信息包括预设的认证信息;The master device sends command information to a plurality of the slave devices, where the command information includes preset authentication information;

多个所述从设备获取所述命令信息并根据所述认证信息进行匹配;A plurality of the slave devices obtain the command information and perform matching according to the authentication information;

与所述认证信息匹配成功的所述从设备执行对应的命令。The slave device that is successfully matched with the authentication information executes the corresponding command.

可选地,预先对每一所述从设备分别设定对应的匹配规则;Optionally, setting a corresponding matching rule for each of the slave devices in advance;

所述“根据所述认证信息进行匹配”包括:The "matching according to the authentication information" includes:

各所述从设备依据对应的所述匹配规则对所述认证信息进行匹配;Each of the slave devices matches the authentication information according to the corresponding matching rule;

确定所述从设备是否匹配成功。Determine whether the slave device is successfully matched.

可选地,所述认证信息包括各所述从设备专属的认证信息以及能与至少两个所述从设备匹配成功的认证信息。Optionally, the authentication information includes authentication information specific to each of the slave devices and authentication information that can be successfully matched with at least two of the slave devices.

可选地,所述命令信息还包括操作信息;Optionally, the command information further includes operation information;

所述“与所述认证信息匹配成功的所述从设备执行对应的命令”包括:The "execution of the corresponding command by the slave device that is successfully matched with the authentication information" includes:

与所述认证信息匹配成功的所述从设备依据所述操作信息执行对应的命令。The slave device that is successfully matched with the authentication information executes the corresponding command according to the operation information.

可选地,所述“与所述认证信息匹配成功的所述从设备执行对应的命令”包括:Optionally, the "execution of the corresponding command by the slave device that is successfully matched with the authentication information" includes:

与所述认证信息匹配成功的所述从设备获取所述主设备发送的操作信息;The slave device that is successfully matched with the authentication information obtains the operation information sent by the master device;

与所述认证信息匹配成功的所述从设备依据所述操作信息执行对应的命令。The slave device that is successfully matched with the authentication information executes the corresponding command according to the operation information.

可选地,所述主设备和多个所述从设备分别建立有通信协定,每一所述通信协定包括对所述命令信息中内容的规定;Optionally, the master device and a plurality of the slave devices respectively establish a communication agreement, and each of the communication agreements includes a specification for the content in the command information;

所述从设备在接收到所述命令信息后,还包括:After receiving the command information, the slave device further includes:

所述从设备对所述命令信息进行判断,将不符合对应所述通信协定的所述命令信息确定为所述从设备的异常命令信息。The slave device judges the command information, and determines the command information that does not conform to the corresponding communication protocol as abnormal command information of the slave device.

为实现上述目的,本发明还提供了一种基于SPI的通信装置,包括:To achieve the above object, the present invention also provides a communication device based on SPI, comprising:

主设备和多个从设备,所述主设备与多个所述从设备通过SPI总线连接;a master device and a plurality of slave devices, the master device and a plurality of the slave devices are connected through the SPI bus;

所述主设备包括发送模块;所述从设备包括匹配模块和执行模块;The master device includes a sending module; the slave device includes a matching module and an execution module;

所述发送模块用于向多个所述从设备发送命令信息,所述命令信息包括认证信息;The sending module is configured to send command information to a plurality of the slave devices, where the command information includes authentication information;

所述匹配模块用于获取所述命令信息并根据所述认证信息进行匹配;The matching module is configured to obtain the command information and perform matching according to the authentication information;

与所述认证信息匹配成功的所述从设备的所述执行模块用于执行对应的命令。The execution module of the slave device that is successfully matched with the authentication information is configured to execute a corresponding command.

可选地,所述主设备的一个片选端口分别与各所述从设备电连接,通过所述片选端口发送片选信号给各所述从设备以控制所述主设备和所述从设备之间的通讯。Optionally, a chip select port of the master device is electrically connected to each of the slave devices, and a chip select signal is sent to each of the slave devices through the chip select port to control the master device and the slave device. communication between.

为实现上述目的,本发明还提供了一种电子设备,包括:To achieve the above object, the present invention also provides an electronic device, comprising:

处理器;processor;

存储器,其中存储有所述处理器的可执行指令;a memory in which executable instructions for the processor are stored;

其中,所述处理器配置为经由执行所述可执行指令来执行如上所述的基于SPI的通信方法。Wherein, the processor is configured to execute the SPI-based communication method as described above by executing the executable instructions.

为实现上述目的,本发明还提供了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如上所述的基于SPI的通信方法。In order to achieve the above object, the present invention also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned SPI-based communication method is implemented.

本发明还提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。电子设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该电子设备执行上述基于SPI的通信方法。The present invention also provides a computer program product or computer program comprising computer instructions stored in a computer-readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the above-mentioned SPI-based communication method.

本发明通过主设备向多个从设备发送包括预设的认证信息的命令信息,并且每个从设备在接收到命令信息后,对认证信息进行匹配,与认证信息匹配成功的从设备才可执行对应的命令,从而实现主设备对多个从设备的选用控制以及信息交流,主设备可根据发送的命令信息中的认证信息的不同,使得不同从设备对主设备进行响应,不需要再通过片选信号对从设备进行选择,节省了主设备的GPIO口资源,降低了硬件设计的复杂度。In the present invention, the master device sends command information including preset authentication information to a plurality of slave devices, and each slave device matches the authentication information after receiving the command information, and only the slave device that successfully matches the authentication information can execute the command. Corresponding commands, so as to realize the selection control and information exchange of the master device to multiple slave devices. The master device can make different slave devices respond to the master device according to the different authentication information in the sent command information, without the need to pass the chip. The selection signal selects the slave device, which saves the GPIO port resources of the master device and reduces the complexity of hardware design.

附图说明Description of drawings

图1是现有的基于SPI的主设备与多个从设备的连接示意图。FIG. 1 is a schematic diagram of the connection between an existing SPI-based master device and multiple slave devices.

图2是本发明实施例基于SPI的通信方法的流程图。FIG. 2 is a flowchart of an SPI-based communication method according to an embodiment of the present invention.

图3是本发明一实施例中主设备与多个从设备的信息传递图。FIG. 3 is a diagram of information transfer between a master device and a plurality of slave devices in an embodiment of the present invention.

图4是本发明另一实施例中的主设备与多个从设备的信息传递图。FIG. 4 is a diagram of information transfer between a master device and a plurality of slave devices in another embodiment of the present invention.

图5是本发明实施例基于SPI的通信装置的示意框图。FIG. 5 is a schematic block diagram of an SPI-based communication device according to an embodiment of the present invention.

图6是采用了本发明技术方案的主设备与多个从设备的连接示意图。FIG. 6 is a schematic diagram of the connection between a master device and a plurality of slave devices using the technical solution of the present invention.

图7是本发明实施例电子设备的示意框图。FIG. 7 is a schematic block diagram of an electronic device according to an embodiment of the present invention.

具体实施方式Detailed ways

为了详细说明本发明的技术内容、构造特征、所实现目的及效果,以下结合实施方式并配合附图详予说明。In order to describe in detail the technical content, structural features, achieved objects and effects of the present invention, detailed descriptions are given below with reference to the embodiments and the accompanying drawings.

请参阅图1,图1为现有的主设备与多个从设备通过SPI总线连接的示意图,其中,为了能够实现主设备对多个从设备进行选用控制,需要在主设备上设置与从设备数量对应的多个片选信号端口(SS),主设备的片选信号端口分别与对应的从设备连接,主设备通过片选信号端口传输预先设定的使能信号可控制对应从设备是否响应主设备,如当从设备均以接收到的低电平信号为有效的片选信号时,主设备可通过拉低对目标从设备的片选信号,进而与目标从设备进行通信,但是,目前该技术需要占用大量的GPIO口资源,主、从设备之间连线繁琐,为此,本发明公开了一种基于SPI的通信方法,能够实现主设备对多个从设备的选用控制和信息交流的同时,不占用过多的GPIO口资源。Please refer to FIG. 1. FIG. 1 is a schematic diagram of an existing master device and multiple slave devices connected through the SPI bus. In order to enable the master device to select and control multiple slave devices, it is necessary to set and Multiple chip select signal ports (SS) corresponding to the number, the chip select signal ports of the master device are respectively connected with the corresponding slave devices, and the master device transmits a preset enable signal through the chip select signal port to control whether the corresponding slave device responds The master device, for example, when the slave devices use the received low-level signal as the valid chip select signal, the master device can communicate with the target slave device by pulling down the chip select signal to the target slave device. However, at present, This technology needs to occupy a large amount of GPIO port resources, and the connection between the master and slave devices is cumbersome. Therefore, the present invention discloses a communication method based on SPI, which can realize the selection control and information exchange between the master device and multiple slave devices. At the same time, it does not occupy too much GPIO port resources.

具体地,请参阅图2,该方法包括:Specifically, referring to Figure 2, the method includes:

S1、主设备向多个从设备发送命令信息,命令信息包括预设的认证信息。S1. The master device sends command information to a plurality of slave devices, where the command information includes preset authentication information.

S2、多个从设备获取命令信息并根据认证信息进行匹配。S2. A plurality of slave devices acquire command information and perform matching according to the authentication information.

S3、与认证信息匹配成功的从设备执行对应的命令。S3. The slave device that is successfully matched with the authentication information executes the corresponding command.

具体来说,主设备与多个从设备之间分别建立有通信协定,通信协定规定了每个从设备所能验证成功的认证信息。Specifically, a communication protocol is established between the master device and multiple slave devices, and the communication protocol specifies authentication information that each slave device can verify successfully.

可以理解的是,每个从设备所能匹配成功的认证信息可以是一个,也可以是多个,可以依照需求设置,本申请在此不作限制。It can be understood that there may be one or more pieces of authentication information that can be successfully matched by each slave device, which can be set as required, which is not limited in this application.

可以理解的是,一个认证信息可以与一个从设备匹配成功,也可以与多个从设备匹配成功,可以依照需求设置,本申请在此不作限制。也就是说,可以对每个从设备设置专属的认证信息,也可以设置与至少两个从设备匹配成功的认证信息,能够实现主设备向多个从设备同时进行控制和信息交流,即是完成对多个从设备的广播动作,相较于传统SPI通过片选信号对从设备控制的方法有利于避免重复的片选操作。It can be understood that one piece of authentication information can be successfully matched with one slave device, or can be successfully matched with multiple slave devices, and can be set as required, which is not limited in this application. That is to say, you can set exclusive authentication information for each slave device, or you can set authentication information that is successfully matched with at least two slave devices, so that the master device can control and exchange information with multiple slave devices at the same time, that is, complete Compared with the traditional SPI method of controlling the slave devices through the chip select signal, the broadcast action for multiple slave devices is beneficial to avoid repeated chip select operations.

可以理解的是,认证信息可以是定义的从设备的地址,也可以是从设备的设备编码,等等,只要能够起到主设备和从设备信息通信之间的身份认证的作用即可,本申请在此不作限制。It can be understood that the authentication information can be the address of the defined slave device, or the device code of the slave device, etc., as long as it can play the role of identity authentication between the information communication between the master device and the slave device, this Application is not limited here.

在一些实施例中,本方法还包括预先对每一从设备分别设定对应的匹配规则;In some embodiments, the method further includes presetting a corresponding matching rule for each slave device;

“根据认证信息进行匹配”包括:"Matching based on authentication information" includes:

各从设备依据对应的匹配规则对认证信息进行匹配;Each slave device matches the authentication information according to the corresponding matching rule;

确定与认证信息匹配成功的从设备。Determine the slave device that matches the authentication information successfully.

具体来说,每一从设备的匹配规则根据对应从设备所能匹配成功的认证信息设定,即是,当主设备发送包括认证信息的命令信息至各个从设备后,各从设备对认证信息判断是否符合各自对应的匹配规则,若符合则将相应匹配规则对应的从设备确定为与认证信息匹配成功的从设备。Specifically, the matching rule of each slave device is set according to the authentication information that can be successfully matched by the corresponding slave device, that is, after the master device sends command information including the authentication information to each slave device, each slave device judges the authentication information. Whether the corresponding matching rules are met, if so, the slave device corresponding to the corresponding matching rule is determined as the slave device that successfully matches the authentication information.

请参阅图3,在一些实施例中,命令信息还包括操作信息;Referring to FIG. 3, in some embodiments, the command information further includes operation information;

步骤S3包括:与所述认证信息匹配成功的所述从设备依据所述操作信息执行对应的命令。Step S3 includes: the slave device that is successfully matched with the authentication information executes a corresponding command according to the operation information.

可以理解的是,操作信息可以包括操作种类、目标寄存器地址和数据信息中的一者或多者组合,也可以不限于上述三者,只要能够使从设备依据操作信息执行对应的命令即可,本申请在此不作限制。一般地,在需要从设备执行复位或者清零命令时,操作信息只需要包括操作种类;在需要从设备执行写数据命令时,操作信息需要包括操作种类、目标寄存器地址和数据信息;在需要从设备执行读数据命令时,操作信息需要包括操作种类、目标寄存器地址。It can be understood that the operation information may include one or more combinations of operation type, target register address and data information, and may not be limited to the above three, as long as the slave device can execute the corresponding command according to the operation information, This application is not limited here. Generally, when the reset or clear command needs to be executed from the device, the operation information only needs to include the operation type; when the slave device needs to execute the write data command, the operation information needs to include the operation type, target register address and data information; When the device executes the read data command, the operation information needs to include the operation type and target register address.

具体地,命令信息的内容可由二进制码构成,如认证信息可以是4bit,操作种类也可以是4bit,目标寄存器地址可以是8bit,数据信息也可以是8bit,当然,以上只是举例说明,可以根据实际应用需求设置,并不应以此为限。通信协定规定了从设备接收到命令信息后,根据命令信息的不同所应该执行的对应命令,下表为主设备与从设备之间通信协定中关于信息格式规范的示例性表格:Specifically, the content of the command information can be composed of binary codes. For example, the authentication information can be 4 bits, the operation type can also be 4 bits, the target register address can be 8 bits, and the data information can also be 8 bits. Application requirements settings should not be limited to this. The communication protocol specifies the corresponding commands that should be executed according to the different command information after the slave device receives the command information. The following table is an exemplary table about the information format specification in the communication agreement between the master device and the slave device:

NameName 8-bit Command8-bit Command 8-bit Address8-bit Address 8-bit Data8-bit Data Broadcast Rest CommandBroadcast Rest Command 8b’0101_10108b’0101_1010 N/AN/A N/AN/A Broadcast Clear CommandBroadcast Clear Command 8b’0101_01008b’0101_0100 N/AN/A N/AN/A Slave Device 1ReadSlave Device 1Read 8b’0010_00118b’0010_0011 8-bit Address8-bit Address 8-bit Read Data8-bit Read Data Slave Device 2ReadSlave Device 2Read 8b’0011_00118b’0011_0011 8-bit Address8-bit Address 8-bit Read Data8-bit Read Data Slave Device 1WriteSlave Device 1Write 8b’0010_00108b’0010_0010 8-bit Address8-bit Address 8-bit Write Data8-bit Write Data Slave Device 2WriteSlave Device 2Write 8b’0011_00108b’0011_0010 8-bit Address8-bit Address 8-bit Write Data8-bit Write Data

其中,8-bit Command中的高四位为认证信息,0010为能使Slave Device 1匹配成功的认证信息,0011为能使Slave Device 2匹配成功的认证信息,0101为能使SlaveDevice 1和Slave Device 2匹配成功的认证信息;低四位为操作种类,0011为读取操作,0010为写入操作,1010为重置操作,0100为清零操作。8-bit Address表示执行命令所指向的目标寄存器的地址。8-bit Data中的8-bit Write Data为写入操作时的数据,8-bitRead Data为读取操作时从目标寄存器读取传输至主设备的数据。Among them, the upper four bits in the 8-bit Command are the authentication information, 0010 is the authentication information that enables Slave Device 1 to match successfully, 0011 is the authentication information that enables Slave Device 2 to successfully match, and 0101 is the authentication information that enables Slave Device 1 and Slave Device 2 The authentication information that matches successfully; the lower four bits are the operation type, 0011 is the read operation, 0010 is the write operation, 1010 is the reset operation, and 0100 is the clearing operation. The 8-bit Address indicates the address of the target register pointed to by the execution command. The 8-bit Write Data in the 8-bit Data is the data during the write operation, and the 8-bit Read Data is the data read from the target register and transmitted to the master device during the read operation.

进一步地,每一通信协定包括对于命令信息中内容的规定;Further, each communication protocol includes provisions for the content of the command information;

多个从设备在接收到命令信息后,还包括:After the multiple slave devices receive the command information, they also include:

各从设备对命令信息进行判断,将不符合对应通信协定的命令信息确定为对应从设备的异常命令信息。Each slave device judges the command information, and determines the command information that does not conform to the corresponding communication protocol as the abnormal command information of the corresponding slave device.

具体来说,各设备可判断接收的命令信息的bit数是否符合对应的通信协定,将bit数不符合通信协定的命令信息确定为异常命令信息;还可以判断命令信息各部分信息是否属于通信协定中规定的内容,以此判断命令信息是否为异常命令信息。通过判断命令信息是否符合通信协定,以此确定命令信息是否为异常命令信息,有利于避免从设备被误控制而执行错误命令。Specifically, each device can determine whether the bit number of the received command information conforms to the corresponding communication protocol, and determine the command information whose bit number does not conform to the communication protocol as abnormal command information; and can also determine whether each part of the command information belongs to the communication protocol. The content specified in , so as to judge whether the command information is abnormal command information. By judging whether the command information conforms to the communication protocol, it is determined whether the command information is abnormal command information, which is beneficial to avoid the slave device being erroneously controlled and executing the wrong command.

请参阅图4,在一些实施例中,命令信息可以仅包括认证信息和操作种类,各从设备在接收到命令信息后,先对认证信息进行匹配认证,匹配成功的从设备再对操作种类进行识别,主设备向从设备发送目标寄存器地址和数据信息,以使匹配成功的从设备成功执行目标命令,而匹配失败的从设备则不对操作种类识别,并使得与主设备进行信息交流的端口呈高阻态,拒绝接收主设备发送的目标寄存器地址和数据信息,图4中的虚线箭头即表示对应的从设备无法接收到操作信息。Referring to FIG. 4 , in some embodiments, the command information may only include authentication information and operation type. After receiving the command information, each slave device first performs matching and authentication on the authentication information, and the successfully matched slave device then performs the operation type. Recognition, the master device sends the target register address and data information to the slave device, so that the successfully matched slave device successfully executes the target command, while the failed matching slave device does not recognize the type of operation, and makes the port that communicates with the master device is displayed. In the high-impedance state, it refuses to receive the target register address and data information sent by the master device. The dotted arrow in Figure 4 indicates that the corresponding slave device cannot receive the operation information.

请参阅图4,在一些实施例中,步骤S3包括:Referring to FIG. 4, in some embodiments, step S3 includes:

与认证信息匹配成功的从设备获取主设备发送的操作信息;The slave device that successfully matches the authentication information obtains the operation information sent by the master device;

与认证信息匹配成功的从设备依据操作信息执行对应的命令。The slave device that successfully matches the authentication information executes the corresponding command according to the operation information.

具体来说,命令信息可仅包括认证信息,各从设备在接收到命令信息后,对认证信息进行匹配认证,匹配成功的从设备可继续接收来自主设备的信息,即接收操作信息,操作信息中可包括操作种类、目标寄存器地址和数据信息,而匹配失败的从设备则使与主设备进行信息交流的端口呈高阻态,拒绝接收来自主设备的信息,图4中的虚线箭头即表示对应的从设备无法接收到操作信息。Specifically, the command information may only include authentication information. After each slave device receives the command information, it matches and authenticates the authentication information. The successfully matched slave device can continue to receive information from the master device, that is, receive operation information, operation information It can include the operation type, target register address and data information, and the slave device that fails to match makes the port that communicates with the master device in a high-impedance state and refuses to receive information from the master device. The dotted arrow in Figure 4 indicates that The corresponding slave device cannot receive operation information.

本发明通过主设备向多个从设备发送包括预设的认证信息的命令信息,并且每个从设备在接收到命令信息后,对认证信息进行匹配,与认证信息匹配成功的从设备才可执行对应的命令,从而实现主设备对多个从设备的选用控制以及信息交流,主设备可根据发送的命令信息中的认证信息的不同,使得不同从设备对主设备进行响应,不需要再通过片选信号对从设备进行选择,节省了主设备的GPIO口资源,降低了硬件设计的复杂度。In the present invention, the master device sends command information including preset authentication information to a plurality of slave devices, and each slave device matches the authentication information after receiving the command information, and only the slave device that successfully matches the authentication information can execute the command. Corresponding commands, so as to realize the selection control and information exchange of the master device to multiple slave devices. The master device can make different slave devices respond to the master device according to the different authentication information in the sent command information, without the need to pass the chip. The selection signal selects the slave device, which saves the GPIO port resources of the master device and reduces the complexity of hardware design.

请参阅图5,本发明还提供了一种基于SPI的通信装置,包括:Please refer to FIG. 5, the present invention also provides a communication device based on SPI, including:

主设备1和多个从设备2,主设备1与多个从设备2通过SPI总线连接;Master device 1 and multiple slave devices 2, the master device 1 and multiple slave devices 2 are connected through the SPI bus;

主设备1包括发送模块100;从设备2包括匹配模块200和执行模块300;The master device 1 includes a sending module 100; the slave device 2 includes a matching module 200 and an execution module 300;

发送模块100用于向多个从设备2发送命令信息,命令信息包括认证信息;The sending module 100 is configured to send command information to multiple slave devices 2, where the command information includes authentication information;

匹配模块200用于获取命令信息以根据认证信息进行匹配;The matching module 200 is configured to obtain command information to match according to the authentication information;

与认证信息匹配成功的从设备2的执行模块300用于执行对应的命令。The execution module 300 of the slave device 2 that is successfully matched with the authentication information is used to execute the corresponding command.

本发明能够实现主设备对多个从设备的选用控制以及信息交流,主设备可根据发送的命令信息中的认证信息的不同,使得不同从设备对主设备进行响应,不需要再通过片选信号对从设备进行选择,节省了主设备的GPIO口资源,降低了硬件设计的复杂度。The invention can realize the selection control and information exchange of the master device to multiple slave devices, and the master device can make different slave devices respond to the master device according to the difference of the authentication information in the sent command information, without the need to pass the chip selection signal. Selecting the slave device saves the GPIO port resources of the master device and reduces the complexity of hardware design.

具体地,请参阅图6,主设备的一个片选端口分别与各从设备电连接,通过片选端口发送片选信号给各从设备以控制主设备和从设备之间的通讯。Specifically, referring to FIG. 6 , a chip select port of the master device is electrically connected to each slave device, and a chip select signal is sent to each slave device through the chip select port to control the communication between the master device and the slave device.

当主设备需要对多个从设备中的其中一者或者多者进行控制和通讯时,主设备可通过片选端口对各从设备发送预设的有效片选信号,使得各从设备可接收到主设备发送的信息;而当主设备与多个从设备不进行通信时,主设备可通过片选端口对各从设备发送预设的无效片选信号,使得各从设备对主设备发送的信息不作响应,有利于避免干扰信息进入从设备之中,避免从设备出现误操作。When the master device needs to control and communicate with one or more of the multiple slave devices, the master device can send a preset valid chip select signal to each slave device through the chip select port, so that each slave device can receive the master device. The information sent by the device; and when the master device does not communicate with multiple slave devices, the master device can send a preset invalid chip select signal to each slave device through the chip select port, so that each slave device does not respond to the information sent by the master device. , which is beneficial to avoid interfering information from entering the slave device and avoid misoperation of the slave device.

请参阅图7,本发明还提供了一种电子设备,包括:Please refer to FIG. 7, the present invention also provides an electronic device, including:

处理器40;processor 40;

存储器50,其中存储有处理器40的可执行指令;a memory 50 in which executable instructions for the processor 40 are stored;

其中,处理器40配置为经由执行可执行指令来执行如上所述的基于SPI的通信方法。Wherein, the processor 40 is configured to execute the SPI-based communication method as described above by executing the executable instructions.

本发明还提供一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现如上所述的基于SPI的通信方法。The present invention also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, implements the above-mentioned SPI-based communication method.

本发明实施例还公开了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。电子设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该电子设备执行如上所述的基于SPI的通信方法。The embodiment of the present invention also discloses a computer program product or computer program, where the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device performs the SPI-based communication method as described above.

应当理解,在本发明实施例中,所称处理器可以是中央处理模块(CentralProcessing Unit,CPU),该处理器还可以是其他通用处理器、数字信号处理器(DigitalSignal Processor,DSP)、专用集成电路(Application Specific IntegratedCircuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。It should be understood that, in this embodiment of the present invention, the so-called processor may be a central processing unit (Central Processing Unit, CPU), and the processor may also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), special integrated Circuit (Application Specific Integrated Circuit, ASIC), off-the-shelf Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.

本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序指令相关的硬件来完成,所述的程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)或随机存储记忆体(RandomAccessMemory,RAM)等。Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above-mentioned embodiments can be implemented by instructing relevant hardware by a computer program, and the program can be stored in a computer-readable storage medium, and the program is During execution, it may include the processes of the embodiments of the above-mentioned methods. The storage medium may be a magnetic disk, an optical disk, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM) or the like.

以上所揭露的仅为本发明的较佳实例而已,不能以此来限定本发明之权利范围,因此依本发明权利要求所作的等同变化,均属于本发明所涵盖的范围。The above disclosures are only preferred examples of the present invention, and cannot be used to limit the scope of rights of the present invention. Therefore, the equivalent changes made according to the claims of the present invention all belong to the scope covered by the present invention.

Claims (10)

1. An SPI-based communication method, adapted to a master device and a plurality of slave devices connected by an SPI bus, comprising:
the master device sends command information to the plurality of slave devices, wherein the command information comprises preset authentication information;
the slave devices acquire the command information and perform matching according to the authentication information;
and the slave equipment which is successfully matched with the authentication information executes a corresponding command.
2. The SPI-based communication method of claim 1,
presetting corresponding matching rules for each slave device in advance;
the "matching according to the authentication information" includes:
the slave equipment matches the authentication information according to the corresponding matching rule;
determining whether the slave device matches successfully.
3. The SPI-based communication method of claim 1,
the authentication information comprises authentication information exclusive to each slave device and authentication information capable of being successfully matched with at least two slave devices.
4. The SPI-based communication method according to claim 1, wherein the command information further comprises operation information;
the "the slave device successfully matched with the authentication information executes the corresponding command" includes:
and the slave equipment which is successfully matched with the authentication information executes a corresponding command according to the operation information.
5. The SPI-based communication method of claim 1,
the "the slave device matching the authentication information successfully executes the corresponding command" includes:
the slave equipment which is successfully matched with the authentication information acquires operation information sent by the master equipment;
and the slave equipment which is successfully matched with the authentication information executes a corresponding command according to the operation information.
6. The SPI-based communication method of claim 4,
the master device and the plurality of slave devices respectively establish communication protocols, and each communication protocol comprises the specification of the content in the command information;
after receiving the command information, the slave device further includes:
and the slave equipment judges the command information and determines the command information which does not conform to the corresponding communication protocol as abnormal command information of the slave equipment.
7. An SPI-based communication device, comprising:
the system comprises a master device and a plurality of slave devices, wherein the master device is connected with the slave devices through an SPI bus;
the master device comprises a sending module; the slave device comprises a matching module and an execution module;
the sending module is used for sending command information to the plurality of slave devices, and the command information comprises authentication information;
the matching module is used for acquiring the command information and matching according to the authentication information;
the execution module of the slave device which is successfully matched with the authentication information is used for executing a corresponding command.
8. The SPI-based communication device of claim 7,
and one chip selection port of the master device is electrically connected with each slave device respectively, and a chip selection signal is sent to each slave device through the chip selection port so as to control the communication between the master device and the slave device.
9. An electronic device, comprising:
a processor;
a memory having stored therein executable instructions of the processor;
wherein the processor is configured to perform the SPI-based communication method of any one of claims 1-6 via execution of the executable instructions.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the SPI-based communication method according to any one of claims 1 to 6.
CN202210755414.XA 2022-06-29 2022-06-29 A kind of communication method and device based on SPI Pending CN115061961A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210755414.XA CN115061961A (en) 2022-06-29 2022-06-29 A kind of communication method and device based on SPI

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210755414.XA CN115061961A (en) 2022-06-29 2022-06-29 A kind of communication method and device based on SPI

Publications (1)

Publication Number Publication Date
CN115061961A true CN115061961A (en) 2022-09-16

Family

ID=83204590

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210755414.XA Pending CN115061961A (en) 2022-06-29 2022-06-29 A kind of communication method and device based on SPI

Country Status (1)

Country Link
CN (1) CN115061961A (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101499046A (en) * 2008-01-30 2009-08-05 鸿富锦精密工业(深圳)有限公司 SPI equipment communication circuit
CN107562666A (en) * 2017-09-26 2018-01-09 威创集团股份有限公司 Method, system and the relevant apparatus of communication between devices based on spi bus
CN108418739A (en) * 2018-02-09 2018-08-17 浙江大学 A Token Ring Networking Method Based on SPI
CN109240971A (en) * 2018-09-26 2019-01-18 威创集团股份有限公司 Communication means, apparatus and system
CN109359073A (en) * 2018-09-18 2019-02-19 深圳吉迪思电子科技有限公司 A kind of communication between devices method and apparatus topological structure based on spi bus
CN109446122A (en) * 2018-09-30 2019-03-08 新华三技术有限公司 The access method and communication equipment of programming device
CN112506839A (en) * 2020-12-07 2021-03-16 天津津航计算技术研究所 One-to-many SPI bus switching method and device
CN113722261A (en) * 2021-09-13 2021-11-30 东南大学 Method for expanding chip selection number and enhancing flexibility of read-write response time by SPI
CN114138703A (en) * 2022-02-07 2022-03-04 成都时识科技有限公司 Method, device and chip for communication based on serial peripheral interface
KR20220052115A (en) * 2020-10-20 2022-04-27 삼성전자주식회사 A display apparatus, an electronic apparatus and methods thereof

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101499046A (en) * 2008-01-30 2009-08-05 鸿富锦精密工业(深圳)有限公司 SPI equipment communication circuit
CN107562666A (en) * 2017-09-26 2018-01-09 威创集团股份有限公司 Method, system and the relevant apparatus of communication between devices based on spi bus
CN108418739A (en) * 2018-02-09 2018-08-17 浙江大学 A Token Ring Networking Method Based on SPI
CN109359073A (en) * 2018-09-18 2019-02-19 深圳吉迪思电子科技有限公司 A kind of communication between devices method and apparatus topological structure based on spi bus
CN109240971A (en) * 2018-09-26 2019-01-18 威创集团股份有限公司 Communication means, apparatus and system
CN109446122A (en) * 2018-09-30 2019-03-08 新华三技术有限公司 The access method and communication equipment of programming device
KR20220052115A (en) * 2020-10-20 2022-04-27 삼성전자주식회사 A display apparatus, an electronic apparatus and methods thereof
CN112506839A (en) * 2020-12-07 2021-03-16 天津津航计算技术研究所 One-to-many SPI bus switching method and device
CN113722261A (en) * 2021-09-13 2021-11-30 东南大学 Method for expanding chip selection number and enhancing flexibility of read-write response time by SPI
CN114138703A (en) * 2022-02-07 2022-03-04 成都时识科技有限公司 Method, device and chip for communication based on serial peripheral interface

Similar Documents

Publication Publication Date Title
US7757020B2 (en) Point-to-point link negotiation method and apparatus
WO2019184444A1 (en) Master-slave configuration communication protocol, method for improving compatibility, and electronic device
WO2021244194A1 (en) Register reading/writing method, chip, subsystem, register group, and terminal
US5978865A (en) System for performing DMA transfers where an interrupt request signal is generated based on the value of the last of a plurality of data bits transmitted
CN105700732A (en) Apparatus, system and method for communication of touch sensor information
WO2023147748A1 (en) Method and apparatus for initializing smart network interface card by server, device, and medium
KR20160037114A (en) Serial peripheral interface
CN110880998A (en) Message transmission method and device based on programmable device
WO2018072640A1 (en) Interface control command processing method and modem equipment
US10936530B2 (en) Method and apparatus for determining link bifurcation availability
WO2023082622A1 (en) Method for designing communication module having master and slave devices compatible, and apparatus
CN115061961A (en) A kind of communication method and device based on SPI
US11288223B2 (en) Bridge chip with function of expanding external devices and associated expansion method
CN108108314B (en) Exchanger system
TWI703446B (en) Interface adapter circuit
CN113282532B (en) Communication device, communication method of communication device and electronic equipment
US20230315672A1 (en) Interface device and computing system including the same
CN104572557B (en) Bus widening method and apparatus
US11757772B2 (en) Stacking switch unit and method used in stacking switch unit
US6700887B1 (en) Packet transfer apparatus which generates access reject command during a DMA transfer
CN103686323A (en) Multiprocessor communication method and system
US7702838B2 (en) Method and apparatus for configuration space extension bus
CN118012812B (en) PCIE link training method, device, electronic device and computer storage medium
US5987558A (en) Method and apparatus for resolving over lapping selection and reselection operations of SCSI bus protocols
CN113886296B (en) Data transmission method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20220916

RJ01 Rejection of invention patent application after publication