This disclosure provides a method for programming and controlling the serial peripheral interface, or SPI, in particular, the method for programming and controlling the SPI in a daisy chain configuration.
SPI is one of the popular serial interfaces. In the SPI protocol, there are a 7-bit address for the target slave device and chip select (CS). Some SPI Slave devices come with built-in address. In the independent SPI connection (e.g.,
A method for programming and controlling of a plurality of slave devices serially connected in a daisy chain configuration using a master device is disclosed. The method includes, broadcasting, from the master device, an initialization data packet to the plurality of slave devices to assign each slave device in the plurality of slave devices a slave address that is unique to said each slave device, assigning a unique slave address to each slave device in the plurality of slave devices by sending an initialization data packet serially from the master device serially through the plurality of slave devices, storing, in each slave device, the assigned slave address, defining a data packet, wherein the data packet comprises a target slave address, a read/write command, a register address, a increment value, and a start address, and transmitting the data packet serially to one or more of the plurality of slave devices until the target address in the data packet matches the slave address stored in one of the plurality of slave devices.
According to some embodiments, the initialization data packet comprises a slave address defines a slave address for each slave device and a location on each slave device in which the slave address is stored. According to some embodiments, the method further includes transmitting, from the master device, the data packet to a first slave device in the plurality of slave devices, comparing the target slave address in the slave address stored in the first slave device, when the target slave address and the slave address stored in the first slave device matches, reporting to the master device, or when the target slave address and the slave address stored in the first slave device does not match, updating the data packet and transmitting the updated data packet to a second slave device in the plurality of slave devices, updating the data packet comprises updating the start address by adding to the current start address the increment value. According to some embodiments, the method further includes comparing the incremented start address with the target slave address, and determining that a slave device is selected when the incremented start address matches the slave device having the target slave address.
According to some embodiments, the method further includes the second slave device transmitting the data packet to the third slave device in the plurality of slave devices by shifting the data packet and incrementing the start address by the predetermined increment value. According to some embodiments, the method further includes comparing the incremented start address with the target slave address; and determining that a slave device is selected when the incremented start address matches the slave device having the target slave address. According to some embodiments, the increment is determined by at least of a number of the plurality of slave devices in the daisy chain. According to some embodiments, the increment is determined by at least a number of bits in the target address of the slave device in the daisy chain. According to some embodiments, the method further includes transmitting the shifted data packet from the second slave device back to the master device. According to some embodiments, the method further includes the third slave device transmitting the shifted data packet from the third slave device back to the master device to complete the daisy chain.
According to some embodiments, the data packet includes at least configuration information of the master device, the slave devices and the daisy chain.
According to some embodiments, the address programming further includes storing the corresponding salve address at a pre-determined register address in the data packet. According to some embodiments, the address programming is conducted when the daisy chain is powered on.
According to some embodiments, a method for programming and controlling of a plurality of slave devices by a master device is disclosed. The method includes deploying the plurality of slave devices and the master device in a daisy chain configuration by connecting the master device to a first of the plurality of slave devices, serially connecting the plurality of slave devices, connecting a last slave device back to the master device to form a daisy chain, defining a data structure, wherein the data packet comprises a target slave address, a read/write bit, a register address and a start address, the master device transmitting the data packet to the first slave device of the plurality of devices, and the first slave device transmitting the data packet to the second slave device in the plurality of slave devices by shifting the data packet and incrementing the start address by a predetermined increment value.
According to some embodiments, the method further includes comparing the incremented start address with the target slave address to determine whether a slave device is selected. According to some embodiments, the method further includes the second slave device transmitting the data packet to the third slave device in the plurality of slave devices by shifting the data packet and incrementing the start address by the predetermined increment value. According to some embodiments, the method further includes comparing the incremented start address with the target slave address to determine whether a slave device is selected. According to some embodiments, the predetermined increment value is a natural number. According to some embodiments, the method further includes the second slave device transmitting the shifted data packet back to the master device to complete the daisy chain. According to some embodiments, the data structure comprises a target slave address, a read/write bit, a register slave address to determine whether a slave device is selected. According to some embodiments, the method further includes the second slave device transmitting the shifted data packet back to the master device to complete the daisy chain.
The teachings of the present invention can be readily understood by considering the following detailed description in conjunction with the accompanying drawings.
Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. In contrast, parallel communication sends several bits as a whole on a link with several parallel channels. Serial communication reduces the number of wires between transmitter and receiver because all receivers are serially connected so an additional receiver can be connected to the last receiver in the existing series of receivers.
The Serial Peripheral Interface (“SPI”) is a synchronous serial communication interface specification which is implemented for short-distance communication, for example, primarily in embedded systems. Typical applications of SPI include, for example, Secure Digital cards and liquid crystal displays.
SPI devices communicate in full duplex mode using a master-slave architecture usually implements a single master, some Atmel devices, however, can support changing roles on the fly depending on an external (SS) pin. The master device, or the controller, originates the frame for reading and writing. Multiple slave-devices may be supported through selection with individual chip select (“CS”), which re sometimes called slave select (“SS”) lines.
SPI is also known as a four-wire serial bus, in comparison to three-, two-, and one-wire serial buses. The SPI may be described as a synchronous serial interface; it is, however, different from the Synchronous Serial Interface (“SSI”) protocol, which is also a four-wire synchronous serial communication protocol. The SSI protocol implements differential signaling and provides only a single simplex communication channel. For any given transaction, SPI implements one-master and multi-slave communication. In this disclosure, “slave” and “slave device” are used interchangeably while “master” and “master device” are used interchangeably.
The SPI bus implements four logic signals: SCLK: Serial Clock (output from master); MOSI: Master Out Slave In (data output from master); MISO: Master In Slave Out (data output from slave); CS/SS: Chip/Slave Select (often active low, output from master to indicate that data is being sent). MOSI on a master connects to MOSI on a slave. MISO on a master connects to MISO on a slave. Slave Select has the same functionality as chip select and is implemented instead of an addressing concept. On a slave-only device, for example, MOSI may be labeled as SDI (Serial Data In) and MISO may be labeled, for example, as SDO (Serial Data Out).
The signal names above can be implemented to label both the master and the slave device pins as well as the signal lines between them. Pin names are always capitalized, for example, “Chip Select,” not “chip select.”
To begin communication, for example, the bus master configures the clock, using a frequency supported by the slave devices, which is typically up to a few MHz. The master then selects the slave device with a logic level 0 on the select line. If a waiting period is required, such as for an analog-to-digital conversion, the master wait for at least that period of time before issuing clock cycles.
During each SPI clock cycle, a full-duplex data transmission occurs. The master sends a bit on the MOSI line and the slave reads it, while the slave sends a bit on the MISO line and the master reads it. This sequence is maintained even when only one-directional data transfer is intended.
Transmissions usually involve two shift registers of certain given word-size, such as eight bits, one in the master and one in the slave; they are connected in a virtual ring topology. Data is usually shifted out with the most significant bit first. On the clock edge, both master and slave shift out a bit and output it on the transmission line to the counterpart. On the next clock edge, at each receiver the bit is sampled from the transmission line and set as a new least-significant bit of the shift register. After the register bits have been shifted out and in, the master and slave have exchanged register values. If more data needs to be exchanged, the shift registers are reloaded and the process is repeated. Transmission may continue for any number of clock cycles. When complete, the master stops toggling the clock signal, and typically deselects the slave.
Transmissions often carried out using eight-bit words. Other word-sizes are also common, however, for example, sixteen-bit words for touch-screen controllers or audio codecs, or twelve-bit words for many digital-to-analog or analog-to-digital converters. Multiple SPI devices may also be daisy-chained to conserve pins.
Every slave on the bus that has not been activated using its chip select line must disregard the input clock and MOSI signals and should not drive MISO, which means it must have a tristate output, although some devices need external tristate buffers to implement this.
In the independent slave configuration, there is an independent chip select
CS line for each slave, which is the way SPI is normally used. The master asserts only one chip select CS at a time.
The SPI port of each slave is configured to send out during the second group of clock-pulses an exact copy of the data it received during the first group of clock pulses.
The whole chain acts as a communication shift register; daisy chaining is often implemented with shift registers to provide a bank of inputs or outputs through the SPI. Each slave copies input to output in the next clock cycle until active low CS line goes high. Such a feature only requires a single CS line from the master, rather than a separate CS line for each slave as illustrated in
Each Slave device has its own and unique address so that it can recognize whether the data it receives is intended for itself. One way to accomplish this is to require Slave devices to be equipped with address pins for hard wiring, which increases cost.
In the parallel configuration in
The Slave device compares the “chain field” with the “Target Slave address field.” If the addresses match, the slave device is the target for the “data packet.” Although this method can identify the target slave device, the additional “chain field” occupies additional bandwidth.
Referring again to
The data in the daisy chain configuration in
According to the table in
In
In order to avoid using the chain field, a “programing address”, or “address programming”, operation is conducted on all slave devices to initialize, or program, the salve device. This “programming address” only needs to be done once upon power on. For example, an address is stored in the “register address” field of 7300 upon initialization when the salve devices are powered on. For example, at the address 0×FF of the first slave device 3200, address#1 is stored, at the address 0×FF of the second slave device 3300, address#2 is stored, at the address 0×FF of the third slave device 3400, address#3 is stored, the starting address. The slave addresses address#1, address#2 and address#3 are programmed and stored in the slave addresses in the corresponding slave devices.
When conducting programming address operation, address#1 is stored at the 0×FF address in the first slave 3200, then address#1 is incremented to become address#2 to be transmitted to the next slave 3300, then address#2 is stored at the address 0×ff of the second slave 3300. Then again address#2 is incremented to become address#3 to be transmitted to the third slave 3400, and address#3 is stored at 0×FF of the third slave 3400. For example, address#1 is 000, 000 is stored at 0×FF of the first slave 3200, then 000 is incremented by 1 to become 001 and is transmitted to the second slave 3300, and 001 is stored at 0×FF of the second slave 3300. Then 001 is further incremented by 1 to become 002 to be transmitted to the third slave 3400, and 002 is stored at 0×FF of the third slave 3400. As such, the chain field is no longer needed in the daisy chain configuration in subsequent transmissions, only the target field is needed, thus saving storage and bandwidth.
As shown in
In the address programming operation, the first field is a “predefined broadcast address”, and the LSB defines a “write” operation. Another field defines the location (for example, 0×FF) in the storage for storing the “slave address” (for example, address#1). The location can be the address of a register, or the address in the memory in the salve device. This field becomes optional when the “location” is predefined. The “increment” is defined in another field for the slave address, and again, if the increment is predefined, this “increment” is optional. Another field defines “start address” for MOSI which is the master output and the slave input. Another field defines the “increment address” for the output of the slave devices.
In the address programming operation, if the slave device confirms that the packet is for programming slave address operation, the first slave device stores the “slave address” in the “location” (for example, 0×FF) in the first slave device. And the “start address” is incremented by the “increment value” to become the incremented address, which is transmitted to the second slave device. The same operation is conducted when the packet is transmitted from the second slave device to the third slave device, and so on.
In the address programming operation, once the salve device (other than the first slave device) confirms that the packet is for programming slave address purpose, the slave device stores the “incremented address” in the “location” and add the “increment value” to the “incremented address” to obtain the updated “incremented address”.
Referring to
Variations of the above embodiments are numerous. The scope of protection is not limited to the embodiments described herein. The scope of protection is only limited by the claims. The scope of the claims shall include all equivalents of the subject matter of the claims.
This application claims the benefit of priority under 35 U.S.C. § 119 to U.S. Provisional Application No. 63/124,494, filed on Dec. 11, 2020, the entire contents of which are incorporated herein by reference.
Number | Date | Country | |
---|---|---|---|
63124494 | Dec 2020 | US |