[go: up one dir, main page]

TWI818834B - Microcontroller and serial peripheral interface system using the same - Google Patents

Microcontroller and serial peripheral interface system using the same Download PDF

Info

Publication number
TWI818834B
TWI818834B TW111148534A TW111148534A TWI818834B TW I818834 B TWI818834 B TW I818834B TW 111148534 A TW111148534 A TW 111148534A TW 111148534 A TW111148534 A TW 111148534A TW I818834 B TWI818834 B TW I818834B
Authority
TW
Taiwan
Prior art keywords
clock
data
spi
peripheral interface
signal
Prior art date
Application number
TW111148534A
Other languages
Chinese (zh)
Other versions
TW202427205A (en
Inventor
曾慶鐿
Original Assignee
新唐科技股份有限公司
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 新唐科技股份有限公司 filed Critical 新唐科技股份有限公司
Priority to TW111148534A priority Critical patent/TWI818834B/en
Priority to CN202310457783.5A priority patent/CN118210746A/en
Application granted granted Critical
Publication of TWI818834B publication Critical patent/TWI818834B/en
Publication of TW202427205A publication Critical patent/TW202427205A/en

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
    • 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
    • G06F13/4291Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus using a clocked protocol

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)
  • Electrophonic Musical Instruments (AREA)

Abstract

A microcontroller and a serial peripheral interface (SPI) system using the same are provided. The SPI system includes a master device and at least one slave device. The slave device is coupled to the master device and configured to communicate with the master device through the SPI. The master device sends one or more of a preset clock signal, an output data signal, and a slave select signal as a clock setting request. The slave device identifies the clock setting request based on the received signal and sends a clock setting data indicating a clock phase and a clock polarity of the slave device in response to the clock setting request. The master device receives the clock setting data and sets the operation mode of the master device to match the clock phase and the clock polarity of the slave device according to the clock setting data.

Description

微控制器及應用其之序列周邊介面系統Microcontrollers and serial peripheral interface systems using them

本發明是有關於一種序列周邊介面通訊技術,且特別是有關於一種微控制器及應用其之序列周邊介面系統。The present invention relates to a serial peripheral interface communication technology, and in particular to a microcontroller and a serial peripheral interface system using the same.

序列周邊介面(Serial Peripheral Interface,SPI)是一種全雙工同步通訊介面,其主要是採用四線制串列傳輸。在主從式SPI系統中,SPI主裝置可以通過SPI連接埠與SPI從屬裝置進行通訊,以交互傳輸資料。因為SPI具有操作簡單、數據傳輸速率高等優點,因此廣泛地被採用在微控制器或其他射頻晶片等器件設計中。Serial Peripheral Interface (SPI) is a full-duplex synchronous communication interface that mainly uses four-wire serial transmission. In a master-slave SPI system, the SPI master device can communicate with the SPI slave device through the SPI port to interactively transmit data. Because SPI has the advantages of simple operation and high data transmission rate, it is widely used in the design of devices such as microcontrollers or other radio frequency chips.

由於實現SPI從屬裝置的器件可能是由不同廠商製造,或是因型號差異造成設定的SPI時序/工作模式也不相同,因此在設置SPI系統時,設計者必須個別地針對SPI從屬裝置的規格進行確認,然後再將SPI主裝置的工作模式與SPI從屬裝置設定為一致。如此造成了SPI系統設置的複雜性,並且因為每次設定都需要人為的確認SPI時序/工作模式,因此人為設定錯誤的風險也難以排除。Since the devices that implement SPI slave devices may be manufactured by different manufacturers, or the set SPI timing/working modes are different due to differences in models, when setting up an SPI system, designers must individually address the specifications of the SPI slave device. Confirm, and then set the working mode of the SPI master device to be consistent with the SPI slave device. This makes the SPI system settings complex, and because each setting requires manual confirmation of the SPI timing/working mode, the risk of human setting errors is difficult to eliminate.

本揭露提出一種微控制器及應用其之序列周邊介面系統,其可降低設定SPI系統的複雜性,並且避免人為設定錯誤的可能性。The present disclosure proposes a microcontroller and a serial peripheral interface system using the microcontroller, which can reduce the complexity of setting the SPI system and avoid the possibility of human setting errors.

本揭露提供一種微控制器,其適於作為主裝置以和從屬裝置通訊。所述微控制器包括處理電路以及SPI電路。SPI電路耦接處理電路,用以將處理電路所產生的資料傳輸給從屬裝置,或將從從屬裝置接收的資料傳輸至處理電路。所述SPI電路在初始化設定模式下,發送預設時脈信號、輸出資料信號以及片選信號其中之一或多者作為時脈設定請求,接收響應時脈設定請求的時脈配置資料,並且依據時脈配置資料設定序列周邊介面電路的時脈極性以及時脈相位。The present disclosure provides a microcontroller that is suitable as a master device to communicate with slave devices. The microcontroller includes processing circuitry and SPI circuitry. The SPI circuit is coupled to the processing circuit and used to transmit data generated by the processing circuit to the slave device, or transmit data received from the slave device to the processing circuit. In the initialization setting mode, the SPI circuit sends one or more of the preset clock signal, the output data signal and the chip select signal as a clock setting request, receives the clock configuration data in response to the clock setting request, and based on The clock configuration data sets the clock polarity and clock phase of the serial peripheral interface circuit.

本揭露提供一種微控制器,其適於作為從屬裝置以和主裝置通訊。所述微控制器包括處理電路以及SPI電路。SPI電路耦接處理電路,用以將從主裝置接收的資料傳輸至處理電路,或將處理電路所產生的資料傳輸給主裝置。所述SPI電路在初始化設定模式下,根據接收到的預設時脈信號、輸入資料信號以及片選信號其中之一或多者識別時脈設定請求,並且響應時脈設定請求發送時脈配置資料,其中時脈配置資料指示序列周邊介面電路的時脈極性以及時脈相位。The present disclosure provides a microcontroller that is suitable as a slave device to communicate with a master device. The microcontroller includes processing circuitry and SPI circuitry. The SPI circuit is coupled to the processing circuit and is used to transmit data received from the host device to the processing circuit, or to transmit data generated by the processing circuit to the host device. In the initialization setting mode, the SPI circuit identifies a clock setting request based on one or more of the received preset clock signal, input data signal and chip select signal, and sends clock configuration data in response to the clock setting request. , where the clock configuration data indicates the clock polarity and clock phase of the sequence peripheral interface circuit.

本揭露提供一種SPI系統,包括主裝置以及至少一從屬裝置。所述從屬裝置耦接主裝置,並且用以通過SPI和主裝置通訊。在初始化設定模式下,主裝置發送預設時脈信號、輸出資料信號以及片選信號其中之一或多者作為時脈設定請求。所述從屬裝置根據接收到的信號識別時脈設定請求,並且響應時脈設定請求發送指示所述從屬裝置的時脈相位以及時脈極性的時脈配置資料。主裝置接收時脈配置資料,並且依據時脈配置資料將主裝置設置為符合所述從屬裝置的時脈相位以及時脈極性。The present disclosure provides an SPI system, including a master device and at least one slave device. The slave device is coupled to the master device and used to communicate with the master device through SPI. In the initialization setting mode, the master device sends one or more of a preset clock signal, an output data signal, and a chip select signal as a clock setting request. The slave device recognizes a clock setting request based on the received signal and sends clock configuration data indicating a clock phase and a clock polarity of the slave device in response to the clock setting request. The master device receives the clock configuration data, and sets the master device to conform to the clock phase and clock polarity of the slave device according to the clock configuration data.

基於上述,本揭露的微控制器及應用其之SPI系統可以在進行初始化設定的期間,使SPI主裝置能夠主動地偵測並獲取SPI從屬裝置的時脈極性和時脈相位,並且自動地將工作模式設置為與SPI從屬裝置一致。如此使用者便無須再個別確認SPI從屬裝置的規格書,再以手動的方式來設定SPI主裝置,因此避免了人為設定錯誤的可能性。Based on the above, the microcontroller of the present disclosure and the SPI system using it can enable the SPI master device to actively detect and obtain the clock polarity and clock phase of the SPI slave device during the initialization setting, and automatically The operating mode is set to be consistent with the SPI slave device. In this way, users no longer need to individually confirm the specifications of the SPI slave device and then manually set the SPI master device, thus avoiding the possibility of human setting errors.

本揭露提出了一種新的微控制器及應用其之序列周邊介面系統,以解決背景技術中提到的問題。為使本揭露的特徵和優點能夠更明顯易懂,下面結合附圖對本發明的具體實施例做詳細的說明。以下敘述含有與本揭露中的示例性實施例相關的特定資訊。本揭露中的附圖和其隨附的詳細敘述僅為示例性實施例。然而,本揭露並不局限於此些示例性實施例。本領域技術人員將會想到本揭露的其它變化與實施例。除非另有說明,否則附圖中的相同或對應的元件可由相同或對應的附圖標號指示。此外,本揭露中的附圖與例示通常不是按比例繪製的,且非旨在與實際的相對尺寸相對應。The present disclosure proposes a new microcontroller and a serial peripheral interface system using the microcontroller to solve the problems mentioned in the background art. In order to make the features and advantages of the present disclosure more obvious and understandable, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings. The following description contains specific information related to the exemplary embodiments of the present disclosure. The drawings and accompanying detailed description in this disclosure are merely exemplary embodiments. However, the present disclosure is not limited to these exemplary embodiments. Other variations and embodiments of the present disclosure will occur to those skilled in the art. Unless otherwise stated, the same or corresponding elements in the drawings may be designated by the same or corresponding reference numerals. Furthermore, the drawings and illustrations in the present disclosure are generally not to scale and are not intended to correspond to actual relative sizes.

圖1為本揭露一實施例之序列周邊介面系統的示意圖。請參照圖1,本實施例的序列周邊介面(Serial Peripheral Interface,SPI)系統10包括SPI主裝置100以及n個SPI從屬裝置200_1~200_n,其中n大於或等於1。FIG. 1 is a schematic diagram of a serial peripheral interface system according to an embodiment of the present disclosure. Referring to FIG. 1 , the Serial Peripheral Interface (SPI) system 10 of this embodiment includes an SPI master device 100 and n SPI slave devices 200_1 to 200_n, where n is greater than or equal to 1.

在本實施例中,SPI主裝置100以及n個SPI從屬裝置200_1~200_n通過SPI的4線串列連接埠進行通訊以交互傳輸資料,其中所述4線串列連接埠包括時脈連接埠SCLK、主出從入連接埠MOSI、主入從出連接埠MISO以及從端選擇連接埠SS。In this embodiment, the SPI master device 100 and the n SPI slave devices 200_1 ~ 200_n communicate through a 4-wire serial port of SPI to interactively transmit data, wherein the 4-wire serial port includes a clock port SCLK , master in and slave out port MOSI, master in and slave out port MISO and slave select port SS.

具體而言,SPI主裝置100的時脈連接埠SCLK、主出從入連接埠MOSI以及主入從出連接埠MISO會分別耦接各SPI從屬裝置200_1~200_n的對應連接埠,並且SPI主裝置100的時脈連接埠SCLK以及主出從入連接埠MOSI會作為信號輸出埠傳輸信號至各SPI從屬裝置200_1~200_n。其中,時脈連接埠SCLK是用以傳輸時脈信號CLK至SPI從屬裝置200_1~200_n,以令SPI從屬裝置200_1~200_n可以利用時脈信號CLK作為通訊時脈。主出從入連接埠MOSI是用以將SPI主裝置100的資料傳輸至SPI從屬裝置200_1~200_n的接口。Specifically, the clock port SCLK, the master-in slave-in port MOSI, and the master-in slave port MISO of the SPI master device 100 are respectively coupled to the corresponding ports of each SPI slave device 200_1~200_n, and the SPI master device The clock port SCLK of 100 and the master input and slave input port MOSI will be used as signal output ports to transmit signals to each SPI slave device 200_1~200_n. The clock connection port SCLK is used to transmit the clock signal CLK to the SPI slave devices 200_1~200_n, so that the SPI slave devices 200_1~200_n can use the clock signal CLK as the communication clock. The master-output-slave-input port MOSI is an interface used to transmit data from the SPI master device 100 to the SPI slave devices 200_1~200_n.

SPI主裝置100的主入從出連接埠MISO則會作為信號輸入埠以接收SPI從屬裝置200_1~200_n所發送之信號,其中主入從出連接埠MISO是用以將SPI從屬裝置200_1~200_n的資料傳輸至SPI主裝置100的接口。The master-input-slave-output port MISO of the SPI master device 100 will be used as a signal input port to receive signals sent by the SPI slave devices 200_1~200_n. The master-input-slave-output port MISO is used to connect the SPI slave devices 200_1~200_n. The data is transmitted to the interface of the SPI master device 100 .

此外,根據系統SPI中從屬裝置200_1~200_n的數量設置,SPI主裝置100可以具有對應從屬裝置200_1~200_n數量的從端選擇連接埠SS1~SSn,其中SPI主裝置100的從端選擇連接埠SS1~SSn會分別耦接從屬裝置200_1~200_n的從端選擇連接埠SS1~SSn。換言之,各SPI從屬裝置200_1~200_n僅會有一個從端選擇連接埠SS1~SSn與SPI主裝置100上對應的從端選擇連接埠SS1~SSn連接,或可說是在SPI從屬模式的設定下,各從屬裝置200_1~200_n僅會有一個對應的從端選擇連接埠SS1~SSn被啟用。SPI主裝置100的從端選擇連接埠SS1~SSn是用以作為信號輸出埠傳輸致能信號至對應的SPI從屬裝置200_1~200_n,其中接收到致能信號的SPI從屬裝置200_1~200_n會被啟用以進行資料傳輸;反之未接收到致能信號的SPI從屬裝置200_1~200_n則會被禁能。In addition, according to the setting of the number of slave devices 200_1 ~ 200_n in the system SPI, the SPI master device 100 may have slave select connection ports SS1 ~ SSn corresponding to the number of slave devices 200_1 ~ 200_n, wherein the slave select connection port SS1 of the SPI master device 100 ~SSn will be coupled to the slave select ports SS1~SSn of the slave devices 200_1~200_n respectively. In other words, each SPI slave device 200_1~200_n only has one slave selection port SS1~SSn connected to the corresponding slave selection port SS1~SSn on the SPI master device 100, or it can be said that under the setting of SPI slave mode , each slave device 200_1~200_n will have only one corresponding slave-side selection port SS1~SSn enabled. The slave select ports SS1~SSn of the SPI master device 100 are used as signal output ports to transmit enable signals to the corresponding SPI slave devices 200_1~200_n. The SPI slave devices 200_1~200_n that receive the enable signals will be enabled. for data transmission; otherwise, the SPI slave devices 200_1~200_n that have not received the enable signal will be disabled.

本實施例的SPI連接埠是以4線串列連接埠為例,但本揭露不以此為限。在一些實施例中,若SPI系統10為一對一的配置(即,n=1),則從端選擇連接埠SS1~SSn可以被省略或禁能,此時的SPI連接埠可以是3線串列連接埠。The SPI connection port in this embodiment is a 4-wire serial connection port as an example, but the disclosure is not limited to this. In some embodiments, if the SPI system 10 is configured in a one-to-one configuration (ie, n=1), the slave selection ports SS1~SSn may be omitted or disabled, and the SPI ports at this time may be 3-wire Serial port.

在本實施例中,SPI主裝置100可以利用如圖2所示的微控制器(底下稱微控制器100)來實施,其中圖2為本揭露一實施例之作為SPI主裝置的微控制器的示意圖。In this embodiment, the SPI master device 100 can be implemented using a microcontroller (hereinafter referred to as the microcontroller 100 ) as shown in Figure 2 , where Figure 2 shows a microcontroller as an SPI master device according to an embodiment of the present disclosure. schematic diagram.

請參照圖2,微控制器100包括處理電路110、SPI電路120以及匯流排控制電路130。處理電路110例如為一中央處理單元(CPU),其用以處理資料存取和運算。SPI電路120通過匯流排控制電路130耦接處理電路110,其中處理電路110所產生的資料會通過匯流排控制電路130傳輸至SPI電路120,SPI電路120會按照其傳輸格式將資料通過主出從入連接埠MOSI傳輸至外部。相反地,SPI電路120從主入從出連接埠MISO所接收到的資料,會進一步通過匯流排控制電路130傳輸至處理電路110。所述匯流排控制電路130可例如是高階周邊匯流排(Advanced Peripheral Bus,APB)控制電路,但本揭露不以此為限。Referring to FIG. 2 , the microcontroller 100 includes a processing circuit 110 , an SPI circuit 120 and a bus control circuit 130 . The processing circuit 110 is, for example, a central processing unit (CPU), which is used to process data access and operations. The SPI circuit 120 is coupled to the processing circuit 110 through the bus control circuit 130. The data generated by the processing circuit 110 will be transmitted to the SPI circuit 120 through the bus control circuit 130. The SPI circuit 120 will transmit the data through the master and slave according to its transmission format. Input port MOSI is transmitted to the outside. On the contrary, the data received by the SPI circuit 120 from the main input and output port MISO will be further transmitted to the processing circuit 110 through the bus control circuit 130 . The bus control circuit 130 may be, for example, an Advanced Peripheral Bus (APB) control circuit, but the disclosure is not limited thereto.

具體而言,在配置SPI系統(如10)時,微控制器100會經控制進入一初始化設定模式。在初始化設定模式下,SPI電路120被設定為主機模式,以使時脈連接埠SCLK、主出從入連接埠MOSI以及從端選擇連接埠SS被設置為信號輸出埠,並且主入從出連接埠MISO被設置為信號輸出埠。此時SPI電路120產生的時脈信號CLK會通過時脈連接埠SCLK,微控制器100的輸出資料信號DOUTm會通過主出從入連接埠MOSI輸出,片選信號SEL則會通過從端選擇連接埠SS輸出。此外,從外部接收的輸入資料信號DINm會通過主入從出連接埠MISO接收。Specifically, when configuring the SPI system (eg 10), the microcontroller 100 will be controlled to enter an initialization setting mode. In the initialization setting mode, the SPI circuit 120 is set to the master mode, so that the clock port SCLK, the master-out slave-in port MOSI, and the slave-side selection port SS are set as signal output ports, and the master-input-slave-out connection Port MISO is set as the signal output port. At this time, the clock signal CLK generated by the SPI circuit 120 will pass through the clock connection port SCLK, the output data signal DOUTm of the microcontroller 100 will be output through the master output and slave input connection port MOSI, and the chip select signal SEL will be connected through the slave end selection Port SS output. In addition, the input data signal DINm received from the outside will be received through the master input and slave output port MISO.

在完成主機模式的設定後,SPI電路120會進一步在初始化設定模式下,通過發送具有特定信號格式的時脈信號CLK、輸出資料信號DOUTm或片選信號SEL,或者是將上述信號以特定時序組合以作為一時脈設定請求。所述特定信號格式及/或信號組合可以被SPI從屬裝置所識別出,進而判定接收到所述時脈設定請求。After completing the setting of the host mode, the SPI circuit 120 will further send the clock signal CLK with a specific signal format, the output data signal DOUTm or the chip select signal SEL in the initialization setting mode, or combine the above signals in a specific timing sequence. as a clock setting request. The specific signal format and/or signal combination can be recognized by the SPI slave device, and then it is determined that the clock setting request is received.

舉例來說,所述特定信號格式可以是具有特定值的輸出資料信號DOUTm,所述特定值可以是易於識別的兩位元組資料,例如為(0x00, 0xFF)。在一些實施例中,所述特定信號格式也可以是頻率交替變化的時脈信號CLK。所述信號組合可例如是以特定頻率的時脈信號CLK搭配具有特定值的輸出資料信號DOUTm。For example, the specific signal format may be an output data signal DOUTm having a specific value, and the specific value may be easily identifiable two-tuple data, such as (0x00, 0xFF). In some embodiments, the specific signal format may also be a clock signal CLK with alternating frequency. The signal combination may be, for example, a clock signal CLK of a specific frequency and an output data signal DOUTm having a specific value.

換言之,SPI電路120可通過發送具特定信號特徵以易於使SPI從屬裝置識別出的時脈信號CLK、輸出資料信號DOUTm以及片選信號SEL其中之一或多者作為所述時脈設定請求。In other words, the SPI circuit 120 may send one or more of the clock signal CLK, the output data signal DOUTm, and the chip select signal SEL as the clock setting request with specific signal characteristics that are easily recognized by the SPI slave device.

在此應注意的是,在初始化設定模式下,由於作為SPI主裝置的微控制器100尚未確認搭配的SPI從屬裝置的工作模式,所以此時發送的時脈信號CLK為一預設時脈信號。It should be noted here that in the initialization setting mode, since the microcontroller 100 as the SPI master device has not yet confirmed the working mode of the paired SPI slave device, the clock signal CLK sent at this time is a default clock signal. .

接著,SPI電路120會接收到SPI從屬裝置響應所述時脈設定請求而發出的輸入資料信號DINm,其中輸入資料信號DINm包含有SPI從屬裝置的時脈配置資料(即,工作模式設定)。SPI電路120從輸入資料信號DINm中識別出時脈配置資料後,即可依據所述時脈配置資料設定其時脈極性以及時脈相位,以令微控制器100和SPI從屬裝置以相同的工作模式通訊,至此完成微控制器100的初始化設定。Next, the SPI circuit 120 receives the input data signal DINm sent by the SPI slave device in response to the clock setting request, where the input data signal DINm includes clock configuration data (ie, operating mode setting) of the SPI slave device. After the SPI circuit 120 identifies the clock configuration data from the input data signal DINm, it can set its clock polarity and clock phase according to the clock configuration data, so that the microcontroller 100 and the SPI slave device work in the same manner. mode communication, the initialization setting of the microcontroller 100 is completed.

在一些實施例中,SPI電路120可包括用以產生時脈信號CLK和片選信號SEL的控制邏輯單元(未繪示)、用以存取資料的移位暫存器(未繪示)以及輸出輸入緩衝單元(未繪示)。所述控制邏輯單元還可用以執行上述有關於發送時脈設定請求的控制以及依據時脈配置資料設定SPI電路的時脈極性以及時脈相位的動作。In some embodiments, the SPI circuit 120 may include a control logic unit (not shown) for generating the clock signal CLK and the chip select signal SEL, a shift register (not shown) for accessing data, and Output input buffer unit (not shown). The control logic unit may also be used to perform the above-mentioned control on sending a clock setting request and set the clock polarity and clock phase of the SPI circuit according to the clock configuration data.

另一方面,SPI從屬裝置200_1~200_n可以利用如圖3所示的微控制器(底下稱微控制器200)來實施,其中圖3為本揭露一實施例之作為SPI從屬裝置的微控制器的示意圖。On the other hand, the SPI slave devices 200_1~200_n can be implemented using a microcontroller (hereinafter referred to as the microcontroller 200) as shown in Figure 3, where Figure 3 shows a microcontroller as an SPI slave device according to an embodiment of the present disclosure. schematic diagram.

請參照圖3,微控制器200包括處理電路210、SPI電路220以及匯流排控制電路230,其中作為SPI從屬裝置的微控制器200和上述作為SPI主裝置的微控制器100在硬體配置和功能上大致相同,其差異僅在於微控制器200的SPI電路220是被設定為從機模式工作。因此,有關於處理電路210、SPI電路220以及匯流排控制電路230的說明可參照上述圖2實施例,於此不再贅述。Referring to Figure 3, the microcontroller 200 includes a processing circuit 210, an SPI circuit 220 and a bus control circuit 230. The microcontroller 200 as an SPI slave device and the above-mentioned microcontroller 100 as an SPI master device are in hardware configuration and The functions are roughly the same, and the only difference is that the SPI circuit 220 of the microcontroller 200 is set to work in slave mode. Therefore, the description of the processing circuit 210, the SPI circuit 220 and the bus control circuit 230 can refer to the above-mentioned embodiment of FIG. 2, and will not be described again here.

具體而言,在配置SPI系統(如10)時,微控制器200會經控制進入一初始化設定模式。在初始化設定模式下,SPI電路220被設定為從機模式,以使時脈連接埠SCLK、主出從入連接埠MOSI以及從端選擇連接埠SS被設置為信號輸入埠,並且主入從出連接埠MISO被設置為信號輸入埠。此時SPI電路220會通過時脈連接埠SCLK接收時脈信號CLK,輸入資料信號DINs(即,SPI主裝置的輸出資料信號DOUTm)會通過主出從入連接埠MOSI接收,並且片選信號SEL會通過從端選擇連接埠SS接收。此外,微控制器200的輸出資料信號DOUTs(即,SPI主裝置的輸入資料信號DINm)會通過主出從入連接埠MISO輸出。Specifically, when configuring the SPI system (eg 10), the microcontroller 200 will be controlled to enter an initialization setting mode. In the initialization setting mode, the SPI circuit 220 is set to the slave mode, so that the clock port SCLK, the master-out slave-in port MOSI, and the slave-side selection port SS are set as signal input ports, and the master-in slave-out port Port MISO is set as the signal input port. At this time, the SPI circuit 220 will receive the clock signal CLK through the clock connection port SCLK, the input data signal DINs (ie, the output data signal DOUTm of the SPI master device) will be received through the master output and slave input connection port MOSI, and the chip select signal SEL Will be received through the slave selected port SS. In addition, the output data signal DOUTs of the microcontroller 200 (ie, the input data signal DINm of the SPI master device) will be output through the master-out slave-in port MISO.

在完成從機模式的設定後,SPI電路220會進一步在初始化設定模式下,根據接收到的時脈信號、輸入資料信號以及片選信號其中之一或多者識別時脈設定請求,並且在判定接收到時脈設定請求時發送包含有時脈配置資料的輸出資料信號DOUTs,其中所述時脈配置資料會指示SPI電路220的時脈極性以及時脈相位,至此完成微控制器200的初始化設定。After completing the slave mode setting, the SPI circuit 220 will further identify the clock setting request according to one or more of the received clock signal, input data signal and chip select signal in the initialization setting mode, and determine When receiving the clock setting request, an output data signal DOUTs containing clock configuration data is sent, wherein the clock configuration data indicates the clock polarity and clock phase of the SPI circuit 220. This completes the initialization setting of the microcontroller 200. .

更具體地說,在配置SPI系統10時,SPI主裝置100和SPI從屬裝置200_1~200_n的工作模式需要被設置為一致,以使SPI主裝置100和SPI從屬裝置200_1~200_n之間的信號依循相同的時序進行取樣和輸出。所述工作模式依據時脈信號CLK的時序配置以及取樣選擇的不同可分為四種不同的工作模式,如圖4所示,其中圖4為本揭露一實施例之序列周邊介面系統在不同工作模式下的時脈配置示意圖。More specifically, when configuring the SPI system 10, the working modes of the SPI master device 100 and the SPI slave devices 200_1~200_n need to be set to be consistent, so that the signals between the SPI master device 100 and the SPI slave devices 200_1~200_n follow Sampling and output are performed at the same timing. The working mode can be divided into four different working modes according to the timing configuration and sampling selection of the clock signal CLK, as shown in Figure 4. Figure 4 shows the serial peripheral interface system in different working modes according to an embodiment of the present disclosure. Schematic diagram of clock configuration in mode.

請參照圖4,所述四種不同的工作模式(模式0~模式3)主要是依照時脈極性CPOL和時脈相位CPHA所定義出。Please refer to Figure 4. The four different working modes (Mode 0~Mode 3) are mainly defined according to clock polarity CPOL and clock phase CPHA.

以時脈極性CPOL來看,根據時脈信號CLK在閒置狀態下維持的準位不同,時脈極性CPOL可以具有兩種狀態,分別為閒置狀態下維持在低準位(CPOL=0)以及閒置狀態下維持在高準位(CPOL=1)。Looking at the clock polarity CPOL, depending on the level at which the clock signal CLK is maintained in the idle state, the clock polarity CPOL can have two states: maintained at a low level in the idle state (CPOL=0) and idle. It remains at a high level (CPOL=1).

以時脈相位CPHA來看,根據採樣時點選擇的不同,時脈相位CPHA可以具有兩種狀態,分別為在時脈信號CLK轉態的第一邊沿/奇數沿進行採樣(CPHA=0)以及在時脈信號CLK轉態的第二邊沿/偶數沿進行採樣(CPHA=1)。Looking at the clock phase CPHA, depending on the selection of the sampling time point, the clock phase CPHA can have two states, namely sampling at the first edge/odd edge of the clock signal CLK transition (CPHA=0) and at The second edge/even edge of the clock signal CLK transition is sampled (CPHA=1).

在上述的設定組合下,即會產生四種不同的工作模式,分別為:時脈信號CLK在閒置時維持在低準位,並且傳輸資料是在時脈信號CLK的上升沿採樣/鎖存(模式0 - CPOL=0,CPHA=0);時脈信號CLK在閒置時維持在低準位,並且傳輸資料是在時脈信號CLK的下降沿採樣/鎖存(模式1 - CPOL=0,CPHA=1);時脈信號CLK在閒置時維持在高準位,並且傳輸資料是在時脈信號CLK的下降沿採樣/鎖存(模式3 - CPOL=1,CPHA=0);以及時脈信號CLK在閒置時維持在高準位,並且傳輸資料是在時脈信號CLK的上升沿採樣/鎖存(模式4 - CPOL=1,CPHA=1)。Under the above setting combination, four different working modes will be generated, namely: the clock signal CLK is maintained at a low level when idle, and the transmitted data is sampled/latched on the rising edge of the clock signal CLK ( Mode 0 - CPOL=0, CPHA=0); the clock signal CLK is maintained at a low level when idle, and the transmission data is sampled/latched on the falling edge of the clock signal CLK (Mode 1 - CPOL=0, CPHA =1); the clock signal CLK remains at a high level when idle, and the transmitted data is sampled/latched on the falling edge of the clock signal CLK (Mode 3 - CPOL=1, CPHA=0); and the clock signal CLK remains at a high level when idle, and the transmitted data is sampled/latched on the rising edge of the clock signal CLK (Mode 4 - CPOL=1, CPHA=1).

由於SPI從屬裝置200_1~200_n一般僅支援單一工作模式,因此在SPI系統10中SPI主裝置100需要配合SPI從屬裝置200_1~200_n的工作模式去進行設定,以使SPI主裝置100和SPI從屬裝置200_1~200_n的工作模式一致。Since the SPI slave devices 200_1~200_n generally only support a single working mode, the SPI master device 100 in the SPI system 10 needs to be set in accordance with the working modes of the SPI slave devices 200_1~200_n, so that the SPI master device 100 and the SPI slave device 200_1 The working mode of ~200_n is consistent.

在本實施例中,通過上述微控制器100和200在初始化設定模式下的運作配置, SPI主裝置能夠主動地偵測並獲取SPI從屬裝置的時脈極性CPOL和時脈相位CPHA,並且將工作模式設置為與SPI從屬裝置一致。如此使用者便無須再個別確認SPI從屬裝置的規格書,再以手動的方式來設定SPI主裝置,因此避免了人為設定錯誤的可能性。In this embodiment, through the operation configuration of the above-mentioned microcontrollers 100 and 200 in the initialization setting mode, the SPI master device can actively detect and obtain the clock polarity CPOL and clock phase CPHA of the SPI slave device, and will work Mode is set to be consistent with the SPI slave device. In this way, users no longer need to individually confirm the specifications of the SPI slave device and then manually set the SPI master device, thus avoiding the possibility of human setting errors.

上述圖2和圖3實施例分別是以作為SPI主裝置的微控制器100和作為SPI從屬裝置的微控制器200的角度出發,說明微控制器100和200在初始化設定模式下的運作配置。底下圖5進一步以SPI系統整體的角度來說明上述的初始化設定的步驟流程,其中圖5為本揭露一實施例之序列周邊介面系統的初始化設定方法的步驟流程圖。The above embodiments of FIG. 2 and FIG. 3 respectively illustrate the operating configurations of the microcontrollers 100 and 200 in the initialization setting mode from the perspective of the microcontroller 100 as an SPI master device and the microcontroller 200 as an SPI slave device. Figure 5 below further illustrates the above-mentioned initialization setting step flow from the perspective of the overall SPI system. Figure 5 is a step flow chart of the initialization setting method of the serial peripheral interface system according to an embodiment of the present disclosure.

請同時參照圖1和圖5,在SPI系統進入初始化設定模式時,SPI主裝置100會發送預設時脈信號、輸出資料信號以及片選信號其中之一或多者作為時脈設定請求(步驟S110)。Please refer to Figure 1 and Figure 5 at the same time. When the SPI system enters the initialization setting mode, the SPI master device 100 will send one or more of the preset clock signal, output data signal and chip select signal as a clock setting request (step S110).

當SPI從屬裝置200_1~200_n接收到SPI主裝置發送的信號時,SPI從屬裝置200_1~200_n會根據接收到的信號識別該時脈設定請求(步驟S120)。When the SPI slave devices 200_1 ~ 200_n receive the signal sent by the SPI master device, the SPI slave device 200_1 ~ 200_n will identify the clock setting request according to the received signal (step S120).

當SPI從屬裝置200_1~200_n從接收到的信號中識別出時脈設定請求時,SPI從屬裝置200_1~200_n會進一步響應所述時脈設定請求而通過主入從出連接埠MISO發送包含有時脈配置資料的資料信號(步驟S130),其中所述時脈配置資料是指示從屬裝置200_1~200_n的時脈相位以及時脈極性的設定。When the SPI slave devices 200_1 ~ 200_n recognize the clock setting request from the received signal, the SPI slave devices 200_1 ~ 200_n will further respond to the clock setting request and send a clock signal including the clock through the master-input-slave-out port MISO. A data signal of configuration data (step S130), wherein the clock configuration data indicates settings of clock phases and clock polarities of the slave devices 200_1~200_n.

當SPI主裝置100接收到SPI從屬裝置200_1~200_n發送的資料信號時,SPI主裝置100會從中識別出時脈配置資料(步驟S140),並且依據識別出的時脈配置資料將SPI主裝置100設置為符合SPI從屬裝置200_1~200_n的時脈極性CPOL以及時脈相位CPHA(步驟S150)。When the SPI master device 100 receives the data signal sent by the SPI slave devices 200_1~200_n, the SPI master device 100 will identify the clock configuration data therefrom (step S140), and use the SPI master device 100 according to the identified clock configuration data. Set to match the clock polarity CPOL and clock phase CPHA of the SPI slave devices 200_1 to 200_n (step S150).

為了更具體的闡述上述SPI系統10初始化設定的流程,底下列舉兩種不同的具體實施範例來進行說明。In order to explain the above-mentioned initialization setting process of the SPI system 10 in more detail, two different specific implementation examples are listed below for description.

請先參照圖6和圖7,其中圖6為依照圖5之一範例實施例之序列周邊介面系統進行初始化設定時的交互流程圖,並且圖7為依照圖6實施例之序列周邊介面系統的信號時序圖。Please refer to FIGS. 6 and 7 . FIG. 6 is an interaction flow chart during initialization of the serial peripheral interface system according to the exemplary embodiment of FIG. 5 , and FIG. 7 is an interactive flow chart of the serial peripheral interface system according to the embodiment of FIG. 6 . Signal timing diagram.

在本實施例的SPI系統中是以一對一配置的架構來進行說明,但本揭露不以此為限。此外,本實施例的SPI主裝置100例如是預設以模式0(CPOL=0,CPHA=0)進行信號傳輸,所以預設時脈信號CLK在閒置狀態下為低準位,並且輸出資料信號DOUTm是在預設時脈信號CLK的上升沿採樣。本實施例的SPI從屬裝置200是被配置為以模式3(CPOL=1,CPHA=1)進行信號傳輸為例。In the SPI system of this embodiment, a one-to-one configuration architecture is used for description, but the disclosure is not limited to this. In addition, the SPI master device 100 of this embodiment is, for example, preset to perform signal transmission in mode 0 (CPOL=0, CPHA=0), so the preset clock signal CLK is low level in the idle state and outputs a data signal. DOUTm is sampled on the rising edge of the preset clock signal CLK. The SPI slave device 200 in this embodiment is configured to perform signal transmission in mode 3 (CPOL=1, CPHA=1) as an example.

首先,在進行初始化設定時,SPI主裝置100會發送預設時脈信號CLK以及包含有極性設定請求SRPOL的輸出資料信號DOUTm給SPI從屬裝置200(步驟S210m)。First, during initialization setting, the SPI master device 100 sends the preset clock signal CLK and the output data signal DOUTm including the polarity setting request SRPOL to the SPI slave device 200 (step S210m).

所述極性設定請求SRPOL可以是以特定的資料格式來表示,例如是兩位元組資料DT1和DT2。如圖7的時框F1所示,SPI主裝置100發送的兩位元組資料DT1和DT2例如為(0x00,0xFF)。The polarity setting request SRPOL may be expressed in a specific data format, such as two-bit data DT1 and DT2. As shown in time frame F1 of FIG. 7 , the two-bit data DT1 and DT2 sent by the SPI master device 100 are, for example, (0x00, 0xFF).

當SPI從屬裝置200接收到SPI主裝置100發送的輸出資料信號DOUTm時,SPI從屬裝置200會基於兩位元組資料DT1和DT2識別出SPI主裝置100所發出的信號為一極性設定請求SRPOL(步驟S210s),並且響應於極性設定請求SRPOL而發出高準位H或低準位L的輸出資料信號DOUTs以指示時脈極性CPOL的設定值(步驟S220s)。When the SPI slave device 200 receives the output data signal DOUTm sent by the SPI master device 100, the SPI slave device 200 will recognize based on the two-bit data DT1 and DT2 that the signal sent by the SPI master device 100 is a polarity setting request SRPOL ( Step S210s), and in response to the polarity setting request SRPOL, an output data signal DOUTs with a high level H or a low level L is issued to indicate the setting value of the clock polarity CPOL (step S220s).

在本實施例中,由於SPI從屬裝置200是被配置為工作在模式3,因此SPI從屬裝置200會在步驟S220s中發送指示時脈極性CPOL設定值為1的高準位H至SPI主裝置100。In this embodiment, since the SPI slave device 200 is configured to operate in mode 3, the SPI slave device 200 will send a high level H indicating that the clock polarity CPOL setting value is 1 to the SPI master device 100 in step S220s. .

另外應注意的是,雖然在當前狀態下,SPI主裝置100和SPI從屬裝置200的工作模式不同,致使SPI從屬裝置200對於接收到的輸出資料信號DOUTm的採樣和輸出可能會有誤差,但因為用於識別極性設定請求SRPOL的位元組資料DT1和DT2具有可易於識別的數值差異,因此即便SPI從屬裝置200對於接收到的信號採樣時點與SPI主裝置100並不一致,也不會造成SPI從屬裝置200無法識別出極性設定請求SRPOL。In addition, it should be noted that although in the current state, the working modes of the SPI master device 100 and the SPI slave device 200 are different, so that the SPI slave device 200 may have errors in sampling and outputting the received output data signal DOUTm, but because The byte data DT1 and DT2 used to identify the polarity setting request SRPOL have easily identifiable numerical differences. Therefore, even if the SPI slave device 200 samples the received signal at a different time point than the SPI master device 100, it will not cause the SPI slave device 100 to fail. The device 200 cannot recognize the polarity setting request SRPOL.

當SPI主裝置100接收到SPI從屬裝置200發送的輸出資料信號DOUTs時,如圖7的時框F2所示,SPI主裝置100會基於高準位H的輸出資料信號DOUTs識別出SPI從屬裝置200的時脈極性CPOL的設定值為1(步驟S220m)。另一方面,SPI主裝置100會進一步發送包含有相位設定請求SRPHA的輸出資料信號DOUTm給SPI從屬裝置200(步驟S230m)。When the SPI master device 100 receives the output data signal DOUTs sent by the SPI slave device 200, as shown in time frame F2 of FIG. 7, the SPI master device 100 will identify the SPI slave device 200 based on the output data signal DOUTs of the high level H. The set value of clock polarity CPOL is 1 (step S220m). On the other hand, the SPI master device 100 further sends the output data signal DOUTm including the phase setting request SRPHA to the SPI slave device 200 (step S230m).

所述相位設定請求SRPHA可以是以相異於極性設定請求SRPOL的特定資料格式來表示,例如是兩位元組資料DT3和DT4。如圖7的時框F2所示,SPI主裝置100發送的兩位元組資料DT3和DT4例如為(0xFF,0x00)。The phase setting request SRPHA may be expressed in a specific data format that is different from the polarity setting request SRPOL, such as two-bit data DT3 and DT4. As shown in time frame F2 of FIG. 7 , the two-bit tuple data DT3 and DT4 sent by the SPI master device 100 are, for example, (0xFF, 0x00).

當SPI從屬裝置200接收到SPI主裝置100發送的輸出資料信號DOUTm時,SPI從屬裝置200會基於兩位元組資料DT3和DT4識別出SPI主裝置100所發出的信號為一相位設定請求SRPHA(步驟S230s),並且響應於相位設定請求SRPHA而發出高準位H或低準位L的輸出資料信號DOUTs以指示時脈相位CPHA的設定值(步驟S240s)。When the SPI slave device 200 receives the output data signal DOUTm sent by the SPI master device 100, the SPI slave device 200 will recognize based on the two-bit data DT3 and DT4 that the signal sent by the SPI master device 100 is a phase setting request SRPHA ( Step S230s), and in response to the phase setting request SRPHA, an output data signal DOUTs of high level H or low level L is issued to indicate the setting value of the clock phase CPHA (step S240s).

在本實施例中,由於SPI從屬裝置200是被配置為工作在模式3,因此SPI從屬裝置200會在步驟S240s中發送指示時脈極性CPOL設定值為1的高準位H至SPI主裝置100。In this embodiment, since the SPI slave device 200 is configured to operate in mode 3, the SPI slave device 200 will send a high level H indicating that the clock polarity CPOL setting value is 1 to the SPI master device 100 in step S240s. .

接著,當SPI主裝置100再次接收到SPI從屬裝置200發送的輸出資料信號DOUTs時,如圖7的時框F3所示,SPI主裝置100會基於高準位H的輸出資料信號DOUTs識別出SPI從屬裝置200的時脈相位CPHA的設定值為1(步驟S240m)。藉此,SPI主裝置100即可依據接收到的時脈極性CPOL以及時脈相位CPHA資訊而將SPI主裝置100的工作模式從預設的模式0調整至模式3,並且完成初始化設定(步驟S250m)。Next, when the SPI master device 100 receives the output data signal DOUTs sent by the SPI slave device 200 again, as shown in time frame F3 of FIG. 7 , the SPI master device 100 will identify the SPI based on the output data signal DOUTs of the high level H. The set value of the clock phase CPHA of the slave device 200 is 1 (step S240m). Thereby, the SPI master device 100 can adjust the working mode of the SPI master device 100 from the default mode 0 to mode 3 according to the received clock polarity CPOL and clock phase CPHA information, and complete the initialization setting (step S250m ).

附帶一提的是,由於SPI主裝置100在時框F3已經完成在初始化設定模式下的時脈設定請求的發送,因此其可重複發送時脈設定請求、發送冗餘資料或不發送資料,圖7是繪示為發送冗餘資料為例,但本揭露不以此為限。Incidentally, since the SPI master device 100 has completed sending the clock setting request in the initialization setting mode in time frame F3, it can repeatedly send the clock setting request, send redundant data or not send data, as shown in FIG. 7 is shown as an example of sending redundant data, but this disclosure is not limited to this.

換言之,在圖6和圖7的範例實施例中,SPI主裝置100所發送的時脈設定請求可分為極性設定請求SRPOL以及相位設定請求SRPHA。而SPI主裝置100的SPI電路是在步驟S210m中發送具有第一資料格式(DT1=0x00,DT2=0xFF)的輸出資料信號DOUTm以作為極性設定請求SRPOL,並且在步驟S230m中發送具有第二資料格式(DT3=0xFF,DT4=0x00)的輸出資料信號DOUTm以作為相位設定請求SRPHA。In other words, in the example embodiments of FIG. 6 and FIG. 7 , the clock setting request sent by the SPI master device 100 can be divided into a polarity setting request SRPOL and a phase setting request SRPHA. The SPI circuit of the SPI master device 100 sends the output data signal DOUTm with the first data format (DT1=0x00, DT2=0xFF) as the polarity setting request SRPOL in step S210m, and sends the second data with the second data format in step S230m. The output data signal DOUTm in the format (DT3=0xFF, DT4=0x00) is used as the phase setting request SRPHA.

其中,為使極性設定請求SRPOL和相位設定請求SRPHA易於識別,本實施例是採用信號差異最顯著的資料DT1~DT4作為識別請求的資料格式。例如在時框F1的兩位元組資料DT1和DT2對應的16位元為(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1),而在時框F2的兩位元組資料DT3和DT4對應的16位元為(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),如此可使不同的設定請求之間具有最大化的位元差異,亦即第一資料格式和第二資料格式中每一位元皆不相同,使得SPI從屬裝置200可較易於識別出極性設定請求SRPOL和相位設定請求SRPHA。Among them, in order to make the polarity setting request SRPOL and the phase setting request SRPHA easy to identify, this embodiment uses the data DT1 to DT4 with the most significant signal difference as the data format of the identification request. For example, the 16 bits corresponding to the two-bit tuple data DT1 and DT2 in time frame F1 are (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 , 1), and the 16 bits corresponding to the two-bit tuple data DT3 and DT4 in time frame F2 are (1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 , 0, 0, 0), this can maximize the bit difference between different setting requests, that is, each bit in the first data format and the second data format is different, so that the SPI slave device 200 The polarity setting request SRPOL and the phase setting request SRPHA can be easily identified.

在上述範例實施例中,雖然極性設定請求SRPOL和相位設定請求SRPHA是分別以兩位元組資料DT1~DT4來實現,但本揭露不以此為限。在一些實施例中,所述極性設定請求SRPOL/相位設定請求SRPHA也可以利用一位元組資料來表示。舉例來說,極性設定請求SRPOL可以設定為0x0F(0000_1111),而相位設定請求SRPHA可以設定為0xF0(1111_0000)。換言之,所述第一資料格式和第二資料格式可以分別利用至少一位元組以上之資料格式來實施。In the above exemplary embodiment, although the polarity setting request SRPOL and the phase setting request SRPHA are implemented using two-bit tuple data DT1 to DT4 respectively, the present disclosure is not limited thereto. In some embodiments, the polarity setting request SRPOL/phase setting request SRPHA can also be represented by one byte data. For example, the polarity setting request SRPOL can be set to 0x0F (0000_1111), and the phase setting request SRPHA can be set to 0xF0 (1111_0000). In other words, the first data format and the second data format can each be implemented using a data format of at least one byte or more.

此外,上述的兩位元組資料DT1~DT4所採用的數值僅是說明範例,實際應用上任何可以使SPI從屬裝置200可以識別出的數值/資料格式都可以被採用作為本實施例的極性設定請求SRPOL和相位設定請求SRPHA。In addition, the values used in the above-mentioned two-tuple data DT1 ~ DT4 are only illustrative examples. In practical applications, any value/data format that can be recognized by the SPI slave device 200 can be used as the polarity setting in this embodiment. Request SRPOL and phase setting request SRPHA.

請參照圖8和圖9,其中圖8為依照圖5之另一範例實施例之序列周邊介面系統進行初始化設定時的交互流程圖,並且圖9為依照圖8實施例之序列周邊介面系統的信號時序圖。Please refer to FIGS. 8 and 9 . FIG. 8 is an interactive flow chart during initialization of the serial peripheral interface system according to another exemplary embodiment of FIG. 5 , and FIG. 9 is an interactive flow chart of the serial peripheral interface system according to the embodiment of FIG. 8 . Signal timing diagram.

在本實施例的SPI系統中同樣是以一對一配置的架構來進行說明,但本揭露不以此為限。此外,類似於上述範例實施例,本實施例的SPI主裝置100也是預設以模式0(CPOL=0,CPHA=0)進行信號傳輸,並且SPI從屬裝置200是被配置為以模式3(CPOL=1,CPHA=1)進行信號傳輸為例。The SPI system in this embodiment is also described using a one-to-one configuration architecture, but the disclosure is not limited to this. In addition, similar to the above exemplary embodiment, the SPI master device 100 of this embodiment is also preset to perform signal transmission in mode 0 (CPOL=0, CPHA=0), and the SPI slave device 200 is configured to perform signal transmission in mode 3 (CPOL =1, CPHA=1) for signal transmission as an example.

首先,在進行初始化設定時,SPI主裝置100會發送預設時脈信號CLK以及包含有時脈設定請求SRCLK的輸出資料信號DOUTm給SPI從屬裝置200(步驟S310m)。First, during initialization setting, the SPI master device 100 sends the preset clock signal CLK and the output data signal DOUTm including the clock setting request SRCLK to the SPI slave device 200 (step S310m).

所述時脈設定請求SRCLK可以是以特定的資料格式來表示,例如是兩位元組資料DT1和DT2。如圖9的時框F1所示,SPI主裝置100發送的兩位元組資料DT1和DT2例如為(0x00,0xFF)。The clock setting request SRCLK may be expressed in a specific data format, such as two-bit data DT1 and DT2. As shown in time frame F1 of FIG. 9 , the two-bit data DT1 and DT2 sent by the SPI master device 100 are, for example, (0x00, 0xFF).

當SPI從屬裝置200接收到SPI主裝置100發送的輸出資料信號DOUTm時,SPI從屬裝置200會基於兩位元組資料DT1和DT2識別出SPI主裝置100所發出的信號為一時脈設定請求SRCLK(步驟S310s),並且響應於極性設定請求SRPOL而發出包含有SPI從屬裝置200之時脈配置資料的輸出資料信號DOUTs給SPI主裝置100(步驟S220s)。When the SPI slave device 200 receives the output data signal DOUTm sent by the SPI master device 100, the SPI slave device 200 will recognize based on the two-bit data DT1 and DT2 that the signal sent by the SPI master device 100 is a clock setting request SRCLK ( Step S310s), and in response to the polarity setting request SRPOL, an output data signal DOUTs including the clock configuration data of the SPI slave device 200 is sent to the SPI master device 100 (step S220s).

在本實施例中,所述時脈配置資料可以是具有特定資料格式的資料信號,其可例如為兩位元組資料DT3和DT4,其中第一位元組資料DT3和第二位元組資料DT4可以分別指示時脈極性CPOL和時脈相位CPHA的設定值。舉例來說,第一位元組資料DT3為0x00可以指示時脈極性CPOL的設定值為0,第一位元組資料DT3為0xFF可以指示時脈極性CPOL的設定值為1;類似地,第二位元組資料DT4為0x00可以指示時脈相位CPHA的設定值為0,第二位元組資料DT4為0xFF可以指示時脈相位CPHA的設定值為1。換言之,在兩位元組資料DT3和DT4組成的時脈配置資料中,其中的部分位元(即,第一位元組資料DT3)可被識別為極性配置資料,而其中另一部分位元(即,第二位元組資料DT4)可被識別為相位配置資料。In this embodiment, the clock configuration data may be a data signal with a specific data format, which may be, for example, two-byte data DT3 and DT4, where the first byte data DT3 and the second byte data DT4 can indicate the setting values of clock polarity CPOL and clock phase CPHA respectively. For example, the first tuple data DT3 is 0x00 to indicate that the clock polarity CPOL is set to 0, and the first tuple data DT3 is 0xFF to indicate that the clock polarity CPOL is set to 1; similarly, the first tuple data DT3 is 0xFF. The two-byte data DT4 is 0x00 to indicate that the clock phase CPHA is set to 0, and the second byte data DT4 is 0xFF to indicate that the clock phase CPHA is set to 1. In other words, in the clock configuration data composed of the two-bit tuple data DT3 and DT4, some of the bits (ie, the first bit of the tuple data DT3) can be identified as the polarity configuration data, while the other part of the bits (ie, the first bit of the tuple data DT3) can be identified as the polarity configuration data. That is, the second byte data DT4) can be identified as phase configuration data.

藉此,即可利用兩位元組資料DT3和DT4來包含SPI從屬裝置200的工作模式資訊。Thereby, the two-bit data DT3 and DT4 can be used to contain the working mode information of the SPI slave device 200 .

接著,當SPI主裝置100接收到SPI從屬裝置200發送的輸出資料信號DOUTs時,如圖9的時框F2所示,SPI主裝置100會基於第一位元組資料DT3識別出SPI從屬裝置200的時脈極性CPOL的設定值為1,並且基於第二位元組資料DT4識別出SPI從屬裝置200的時脈相位CPHA的設定值為1(步驟S320m)。因此, SPI主裝置100即可依據接收到的時脈極性CPOL以及時脈相位CPHA資訊而將SPI主裝置100的工作模式從預設的模式0調整至模式3,並且完成初始化設定(步驟S330m)。Next, when the SPI master device 100 receives the output data signal DOUTs sent by the SPI slave device 200, as shown in time frame F2 of FIG. 9, the SPI master device 100 will identify the SPI slave device 200 based on the first bit of tuple data DT3. The set value of the clock polarity CPOL is 1, and the set value of the clock phase CPHA of the SPI slave device 200 is identified as 1 based on the second byte data DT4 (step S320m). Therefore, the SPI master device 100 can adjust the working mode of the SPI master device 100 from the default mode 0 to mode 3 according to the received clock polarity CPOL and clock phase CPHA information, and complete the initialization setting (step S330m). .

附帶一提的是,由於SPI主裝置100在時框F2已經完成在初始化設定模式下的時脈設定請求的發送,因此其可重複發送時脈設定請求SRCLK、發送冗餘資料或不發送資料,圖9是繪示為重複發送以位元組資料DT1和DT2表示之時脈設定請求SRCLK為例,但本揭露不以此為限。Incidentally, since the SPI master device 100 has completed sending the clock setting request in the initialization setting mode in time frame F2, it can repeatedly send the clock setting request SRCLK, send redundant data or not send data. FIG. 9 shows an example of repeatedly sending the clock setting request SRCLK represented by byte data DT1 and DT2, but the disclosure is not limited to this.

相較於前述圖6和圖7實施例而言,本實施例通過使SPI從屬裝置200一次性回傳包含有時脈極性和時脈相位資訊的輸出資料信號的方式,使得初始化設定的流程可以進一步簡化。Compared with the aforementioned embodiments of FIG. 6 and FIG. 7 , this embodiment allows the SPI slave device 200 to return an output data signal including clock polarity and clock phase information at one time, so that the initialization setting process can be Further simplification.

綜上所述,微控制器及應用其之SPI系統可以在進行初始化設定的期間,使SPI主裝置能夠主動地偵測並獲取SPI從屬裝置的時脈極性和時脈相位,並且自動地將工作模式設置為與SPI從屬裝置一致。如此使用者便無須再個別確認SPI從屬裝置的規格書,再以手動的方式來設定SPI主裝置,因此避免了人為設定錯誤的可能性。To sum up, the microcontroller and the SPI system using it can enable the SPI master device to actively detect and obtain the clock polarity and clock phase of the SPI slave device during the initialization setting, and automatically work Mode is set to be consistent with the SPI slave device. In this way, users no longer need to individually confirm the specifications of the SPI slave device and then manually set the SPI master device, thus avoiding the possibility of human setting errors.

10:SPI系統 100:SPI主裝置/微控制器 110、210:處理電路 120、220:SPI電路 130、230:匯流排控制電路 200、200_1~200_n:SPI從屬裝置/微控制器 CLK:時脈信號 CPOL:時脈極性 CPHA:時脈相位 DOUTm、DOUTs:輸出資料信號 DINm、DINs:輸入資料信號 DT1~DT4:位元組資料 DUMMY:冗餘資料 F1、F2、F3:時框 MOSI:主出從入連接埠 MISO:主入從出連接埠 SCLK:時脈連接埠 SS、SS1~SSn:從端選擇連接埠 SEL:片選信號 S110~S150:SPI系統的初始化設定方法的步驟 S210m~S250m、S310m~S330m:SPI主裝置的初始化設定方法的步驟 S210s~S240s、S310s~S320s:SPI從屬裝置的初始化設定方法的步驟10:SPI system 100:SPI master/microcontroller 110, 210: Processing circuit 120, 220: SPI circuit 130, 230: Bus control circuit 200, 200_1~200_n: SPI slave device/microcontroller CLK: clock signal CPOL: clock polarity CPHA: clock phase DOUTm, DOUTs: output data signal DINm, DINs: input data signal DT1~DT4: byte data DUMMY: redundant data F1, F2, F3: time frame MOSI: master out and slave in port MISO: master input slave output port SCLK: Clock port SS, SS1~SSn: Slave port selection SEL: chip select signal S110~S150: Steps of initialization setting method of SPI system S210m~S250m, S310m~S330m: Steps of initialization setting method of SPI master device S210s~S240s, S310s~S320s: Steps of initialization setting method of SPI slave device

圖1為本揭露一實施例之序列周邊介面系統的示意圖; 圖2為本揭露一實施例之作為SPI主裝置的微控制器的示意圖; 圖3為本揭露一實施例之作為SPI從屬裝置的微控制器的示意圖; 圖4為本揭露一實施例之序列周邊介面系統在不同工作模式下的時脈配置示意圖; 圖5為本揭露一實施例之序列周邊介面系統的初始化設定方法的步驟流程圖; 圖6為依照圖5之一範例實施例之序列周邊介面系統進行初始化設定時的交互流程圖; 圖7為依照圖6實施例之序列周邊介面系統的信號時序圖; 圖8為依照圖5之另一範例實施例之序列周邊介面系統進行初始化設定時的交互流程圖;以及 圖9為依照圖8實施例之序列周邊介面系統的信號時序圖。 FIG. 1 is a schematic diagram of a serial peripheral interface system according to an embodiment of the present disclosure; FIG. 2 is a schematic diagram of a microcontroller serving as an SPI master device according to an embodiment of the present disclosure; FIG. 3 is a schematic diagram of a microcontroller serving as an SPI slave device according to an embodiment of the present disclosure; FIG. 4 is a schematic diagram of the clock configuration of the serial peripheral interface system in different operating modes according to an embodiment of the present disclosure; FIG. 5 is a step flow chart of an initialization setting method of the serial peripheral interface system according to an embodiment of the present disclosure; Figure 6 is an interaction flow chart during initialization of the serial peripheral interface system according to the exemplary embodiment of Figure 5; Figure 7 is a signal timing diagram of the serial peripheral interface system according to the embodiment of Figure 6; Figure 8 is an interaction flow chart during initialization of the serial peripheral interface system according to another exemplary embodiment of Figure 5; and FIG. 9 is a signal timing diagram of the serial peripheral interface system according to the embodiment of FIG. 8 .

S110~S150:序列周邊介面系統的初始化設定方法的步驟 S110~S150: Steps of initialization setting method of serial peripheral interface system

Claims (10)

一種微控制器,適於作為一主裝置以和一從屬裝置通訊,該微控制器包括: 一處理電路;以及 一序列周邊介面(Serial Peripheral Interface)電路,耦接該處理電路,用以將該處理電路所產生的資料傳輸給該從屬裝置,或將從該從屬裝置接收的資料傳輸至該處理電路, 其中,該序列周邊介面電路在一初始化設定模式下,發送一預設時脈信號、一輸出資料信號以及一片選信號其中之一或多者作為一時脈設定請求,接收響應該時脈設定請求的一時脈配置資料,並且依據該時脈配置資料設定該序列周邊介面電路的一時脈極性以及一時脈相位。 A microcontroller, suitable as a master device to communicate with a slave device, the microcontroller includes: a processing circuit; and a serial peripheral interface (Serial Peripheral Interface) circuit coupled to the processing circuit for transmitting data generated by the processing circuit to the slave device, or transmitting data received from the slave device to the processing circuit, Wherein, in an initialization setting mode, the serial peripheral interface circuit sends one or more of a preset clock signal, an output data signal and a chip select signal as a clock setting request, and receives a response to the clock setting request. A clock configuration data, and a clock polarity and a clock phase of the sequence peripheral interface circuit are set according to the clock configuration data. 如請求項1所述之微控制器,其中該時脈設定請求包括一極性設定請求以及一相位設定請求,該序列周邊介面電路發送具有一第一資料格式的該輸出資料信號以作為該極性設定請求,並且發送具有一第二資料格式的該輸出資料信號以作為該相位設定請求。The microcontroller of claim 1, wherein the clock setting request includes a polarity setting request and a phase setting request, and the serial peripheral interface circuit sends the output data signal having a first data format as the polarity setting request, and send the output data signal having a second data format as the phase setting request. 如請求項2所述之微控制器,其中該第一資料格式和該第二資料格式分別包括至少一位元組資料,並且該第一資料格式和該第二資料格式中每一位元皆不相同。The microcontroller as claimed in claim 2, wherein the first data format and the second data format respectively include at least one bit of tuple data, and each bit in the first data format and the second data format is Are not the same. 如請求項2所述之微控制器,其中該序列周邊介面電路依據響應於該極性設定請求的該時脈配置資料設定該時脈極性,並且依據響應於該相位設定請求的該時脈配置資料設定該時脈相位。The microcontroller of claim 2, wherein the serial peripheral interface circuit sets the clock polarity based on the clock configuration data responsive to the polarity setting request, and based on the clock configuration data responsive to the phase setting request Set this clock phase. 如請求項1所述之微控制器,其中該時脈配置資料包括至少一位元組資料,該序列周邊介面電路將該時脈配置資料的部分位元識別為一極性配置資料,並且將該時脈配置資料的另一部分位元識別為一相位配置資料。The microcontroller of claim 1, wherein the clock configuration data includes at least one byte of data, and the serial peripheral interface circuit identifies part of the bits of the clock configuration data as a polarity configuration data, and converts the Another part of the clock configuration data is identified as a phase configuration data. 如請求項5所述之微控制器,其中該序列周邊介面電路依據該極性配置資料設定該時脈極性,並且依據響該相位配置資料設定該時脈相位。The microcontroller of claim 5, wherein the serial peripheral interface circuit sets the clock polarity according to the polarity configuration data, and sets the clock phase according to the phase configuration data. 一種微控制器,適於作為一從屬裝置以和一主裝置通訊,該微控制器包括: 一處理電路;以及 一序列周邊介面電路,耦接該處理電路,用以將從該主裝置接收的資料傳輸至該處理電路,或將該處理電路所產生的資料傳輸給該主裝置, 其中,該序列周邊介面電路在一初始化設定模式下,根據接收到的一預設時脈信號、一輸入資料信號以及一片選信號其中之一或多者識別一時脈設定請求,並且響應該時脈設定請求發送一時脈配置資料, 其中,該時脈配置資料指示該序列周邊介面電路的一時脈極性以及一時脈相位。 A microcontroller, suitable as a slave device to communicate with a master device, the microcontroller includes: a processing circuit; and a sequence of peripheral interface circuits coupled to the processing circuit for transmitting data received from the host device to the processing circuit, or transmitting data generated by the processing circuit to the host device, Wherein, in an initialization setting mode, the serial peripheral interface circuit recognizes a clock setting request according to one or more of a received preset clock signal, an input data signal and a chip select signal, and responds to the clock setting request. The setup request sends a clock configuration data, The clock configuration data indicates a clock polarity and a clock phase of the sequence peripheral interface circuit. 如請求項7所述之微控制器,其中: 當該序列周邊介面電路接收到具有一第一資料格式的該輸入資料信號時,該序列周邊介面電路發送指示該時脈極性的該時脈配置資料;以及 當該序列周邊介面電路接收到具有一第二資料格式的該輸入資料信號時,該序列周邊介面電路發送指示該時脈相位的該時脈配置資料。 A microcontroller as claimed in claim 7, wherein: When the serial peripheral interface circuit receives the input data signal having a first data format, the serial peripheral interface circuit sends the clock configuration data indicating the clock polarity; and When the serial peripheral interface circuit receives the input data signal having a second data format, the serial peripheral interface circuit sends the clock configuration data indicating the clock phase. 如請求項7所述之微控制器,其中當該序列周邊介面電路識別出該時脈設定請求時,該序列周邊介面電路發送包括至少一位元組資料的該時脈配置資料,其中該時脈配置資料的部分位元指示該時脈極性,並且該時脈配置資料的另一部分位元指示該時脈相位。The microcontroller of claim 7, wherein when the serial peripheral interface circuit recognizes the clock setting request, the serial peripheral interface circuit sends the clock configuration data including at least one byte of data, wherein the clock Part of the bits in the clock configuration data indicates the clock polarity, and another part of the bits in the clock configuration data indicates the clock phase. 一種序列周邊介面系統,包括: 一主裝置;以及 至少一從屬裝置,耦接該主裝置,並且用以通過一序列周邊介面和該主裝置通訊, 其中,在一初始化設定模式下,該主裝置發送一預設時脈信號、一輸出資料信號以及一片選信號其中之一或多者作為一時脈設定請求, 其中,所述從屬裝置根據接收到的信號識別該時脈設定請求,並且響應該時脈設定請求發送指示所述從屬裝置的一時脈相位以及一時脈極性的一時脈配置資料, 其中,該主裝置接收該時脈配置資料,並且依據該時脈配置資料將該主裝置設置為符合所述從屬裝置的該時脈相位以及該時脈極性。 A serial peripheral interface system, including: a master device; and at least one slave device coupled to the master device and configured to communicate with the master device through a serial peripheral interface, Wherein, in an initialization setting mode, the master device sends one or more of a preset clock signal, an output data signal and a chip select signal as a clock setting request, wherein the slave device identifies the clock setting request according to the received signal, and sends a clock configuration data indicating a clock phase and a clock polarity of the slave device in response to the clock setting request, Wherein, the master device receives the clock configuration data, and sets the master device to conform to the clock phase and the clock polarity of the slave device according to the clock configuration data.
TW111148534A 2022-12-16 2022-12-16 Microcontroller and serial peripheral interface system using the same TWI818834B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
TW111148534A TWI818834B (en) 2022-12-16 2022-12-16 Microcontroller and serial peripheral interface system using the same
CN202310457783.5A CN118210746A (en) 2022-12-16 2023-04-25 Microcontroller and sequence peripheral interface system using same

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW111148534A TWI818834B (en) 2022-12-16 2022-12-16 Microcontroller and serial peripheral interface system using the same

Publications (2)

Publication Number Publication Date
TWI818834B true TWI818834B (en) 2023-10-11
TW202427205A TW202427205A (en) 2024-07-01

Family

ID=89857664

Family Applications (1)

Application Number Title Priority Date Filing Date
TW111148534A TWI818834B (en) 2022-12-16 2022-12-16 Microcontroller and serial peripheral interface system using the same

Country Status (2)

Country Link
CN (1) CN118210746A (en)
TW (1) TWI818834B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI903964B (en) * 2025-01-08 2025-11-01 茂達電子股份有限公司 Dynamic addressing system for data transmission

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TW201133248A (en) * 2010-03-26 2011-10-01 Nuvoton Technology Corp Bus interface and clock frequency control method of bus interface
TW201224763A (en) * 2010-09-27 2012-06-16 Skyworks Solutions Inc Dynamically configurable serial data communication interface
TW201243538A (en) * 2011-04-22 2012-11-01 Wistron Corp Method of dynamically adjusting bus clock and device thereof
TW201418992A (en) * 2012-11-06 2014-05-16 Megawin Technology Co Ltd Data transmission control method and device of serial peripheral interface master device
US20170017584A1 (en) * 2015-07-15 2017-01-19 Microchip Technology Incorporated SPI Interface With Less-Than-8-Bit Bytes And Variable Packet Size

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TW201133248A (en) * 2010-03-26 2011-10-01 Nuvoton Technology Corp Bus interface and clock frequency control method of bus interface
TW201224763A (en) * 2010-09-27 2012-06-16 Skyworks Solutions Inc Dynamically configurable serial data communication interface
TW201243538A (en) * 2011-04-22 2012-11-01 Wistron Corp Method of dynamically adjusting bus clock and device thereof
TW201418992A (en) * 2012-11-06 2014-05-16 Megawin Technology Co Ltd Data transmission control method and device of serial peripheral interface master device
US20170017584A1 (en) * 2015-07-15 2017-01-19 Microchip Technology Incorporated SPI Interface With Less-Than-8-Bit Bytes And Variable Packet Size

Also Published As

Publication number Publication date
CN118210746A (en) 2024-06-18
TW202427205A (en) 2024-07-01

Similar Documents

Publication Publication Date Title
CN102023954B (en) Device with multiple I2C buses, processor, system main board and industrial controlled computer
US10552366B2 (en) Method of communication for master device and slave device on synchronous data bus wherein master and slave devices are coupled in parallel
CN105159860B (en) IIC extends system and method
US6119183A (en) Multi-port switching system and method for a computer bus
CN109313466B (en) System for implementing MXM on PCI card
JPH1083375A (en) Scsi system
JP4565459B2 (en) Method for serial transmission of data between two electronic bus stations and bus station used in the method
CN101208678B (en) Software layer for RS-232 to I2C translation of communications between an integrated circuit and a host
JP2008234222A (en) USB controller and USB controller test method
CN115033515A (en) Master-slave SPI communication method
US5884044A (en) Dedicated DDC integrable multimode communications cell
CN111913904A (en) Method for automatically assigning mutually different addresses to a plurality of slave devices using a master-slave communication protocol and device therefor
TWI818834B (en) Microcontroller and serial peripheral interface system using the same
US7395365B2 (en) Data transfer control system, electronic instrument, program, and data transfer control method
US6880026B2 (en) Method and apparatus for implementing chip-to-chip interconnect bus initialization
CN114996184B (en) Compatible implementation SPI or I 2 Interface module of slave C and data transmission method
CN111858459B (en) Processor and computer
CN219349507U (en) Multiprocessor system, mainboard and electronic equipment
WO2021150653A1 (en) Eusb2 to usb 2.0 data transmission with surplus sync bits
US12436911B2 (en) Interface device and computing system including the same
Sasikumar et al. Design and Implementation of a Protocol Conversion Unit for SPI to I2C communication
CN117033292A (en) I based on APB bus control 2 C interrupt method
CN108494889B (en) Communication circuit and debugging method based on I2C bus
CN114397832A (en) A serial port multi-computer communication circuit and method
US12468648B2 (en) Bridge device having data monitoring function and USB to UART converter having the same