Touch screen driving method for realizing gpio simulation spi communication

GPIO simulates SPI communication, solves the communication instability problem caused by insufficient SPI resources, realizes SPI communication flexibility and compatibility on embedded Linux platform, and improves the security and accuracy of application scope and data transmission.

CN119201787APending Publication Date: 2024-12-27AITIWEIER ELECTRONICS TECH BEIJING
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411221204.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2024-12-27

Smart Images

  • Figure CN119201787A_ABST
    Figure CN119201787A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of touch screen driving, and discloses a touch screen driving method for realizing gpio simulation spi communication, which comprises the following steps of: 1, initializing GPIO (General Purpose Input / Output): firstly, configuring a GPIO pin into a mode suitable for SPI (Serial Peripheral Interface) communication; the method comprises the following steps: configuring MOSI (Master Out Slave In): setting an output mode; the method comprises the following steps: configuring MISO (Master In Slave Out): setting an input mode; an SCK (Serial Clock) is configured, and an output mode is set; the method comprises the following steps: step 1, configuring CS / SS (Chip Select / Slave Select): setting an output mode, and generally keeping a high level (non-selected state), and step 2, preparing data as SPI main equipment, and preparing data to be sent. According to the method for realizing gpio simulation spi communication on the embedded Linux platform, spi communication between the touch screen and the platform is realized under the condition that platform hardware SPI resources are insufficient, and more spi slave devices can also be mounted on the platform in this way, so that the application range of SPI communication is effectively expanded, and convenience is brought to operation and use of operators.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of touch screen driving, and in particular relates to a method for realizing touch screen driving by GPIO simulating SPI communication. Background Art

[0002] SPI communication is a widely used serial communication protocol, mainly used for communication between embedded systems and peripherals. It has the characteristics of high-speed, full-duplex, and synchronous communication. It usually uses four lines for communication, including the clock line (SCLK), the chip select line (CS), the master output slave input line (MOSI), and the master input slave output line (MISO).

[0003] At present, when SPI communication is performing data transmission, when SPI resources are insufficient, the effect and stability of SPI communication will be greatly affected, and even the SPI communication will not be able to operate normally, which will eventually lead to data transmission failure. In addition, when the platform communicates, the number of SPI slave devices that can be mounted on it will be limited, which reduces the application scope of SPI communication and brings great inconvenience to the operator's operation. Therefore, it needs to be improved. Summary of the invention

[0004] The object of the present invention is to provide a method for driving a touch screen that realizes GPIO simulation SPI communication, so as to solve the problems raised in the above background technology.

[0005] In order to achieve the above object, the present invention provides the following technical solution: a method for realizing a touch screen driving of GPIO simulating SPI communication, comprising the following steps:

[0006] Step 1: Initialize GPIO

[0007] First, you need to configure the GPIO pins to a mode suitable for SPI communication;

[0008] Configure MOSI (Master Out Slave In): Set to output mode;

[0009] Configure MISO (Master In Slave Out): Set to input mode;

[0010] Configure SCK (Serial Clock): Set to output mode;

[0011] Configure CS / SS (Chip Select / Slave Select): Set to output mode and usually keep it high (unselected state);

[0012] Step 2: Prepare data

[0013] As the SPI master device, prepare the data to be sent, which will be sent one by one in byte or bit order;

[0014] Step 3: Select the slave device

[0015] Before starting data transmission, set the CS / SS pin to low to select a specific slave device;

[0016] Step 4: Sending and receiving data

[0017] For each byte of data transmitted, the following sub-steps need to be performed:

[0018] 1. Sending Data

[0019] Set the most significant bit (MSB) of the data to be sent to the MOSI pin, generate an SCK pulse (SCK from low to high, then from high to low), after the falling edge of SCK, shift the data and prepare to send the next bit, repeat this process until all bits have been sent;

[0020] 2. Receive data

[0021] Before the rising edge of SCK, the level of the MISO pin will reflect the bit sent by the slave device. After the falling edge of SCK, the state of the MISO pin is read and saved into the bit of the received data.

[0022] 3. Repeat this process until all bits are received;

[0023] Step 5: Complete data transfer

[0024] When all data has been sent and received, set the CS / SS pin high again to release the slave device;

[0025] Step 6: Delay and Synchronization

[0026] Between setting the GPIO pin and generating the SCK pulse, you may need to insert a delay to ensure data stability. This is because the GPIO operation may be very fast, and the external device may need some time to respond to the signal change. The delay can be implemented by a software delay loop or by using a hardware timer.

[0027] Step 7: Process the received data

[0028] The received data usually needs to be reassembled into bytes according to the SPI bit order, which involves bit shifts and OR operations.

[0029] This paper proposes a method to implement gpio simulation spi communication on embedded Linux platform. When the platform hardware SPI resources are insufficient, the spi communication between the touch screen and the platform can be realized. More spi slave devices can also be mounted on the platform in this way, thereby effectively improving the application scope of the SPI communication and bringing convenience to the operator's operation.

[0030] Preferably, the SPI communication described in step 1 supports multiple modes, and different data sampling and shifting timings can be achieved by configuring different combinations of clock polarity (CPOL) and clock phase (CPHA).

[0031] This design ensures the flexibility and compatibility of SPI communication, enables it to adapt to different hardware and software requirements, effectively improves the application scope of the communication, and brings convenience to operators.

[0032] Preferably, the SPI communication described in step one is a full-duplex interface, and data is sent and received simultaneously when the SPI communication is running.

[0033] This design ensures good stability during SPI communication, while also ensuring that there will be no loss in data transmission and ensuring the security of data transmission.

[0034] Preferably, the data transmission of the MISO pin described in step 4 is performed synchronously, and the MISO pin is a dual-channel communication.

[0035] Such a mechanism ensures the accuracy and efficiency of communication, and the MISO pin plays an important role in the SPI communication process. It allows the master device to receive data from the slave device to achieve the effect of two-way communication.

[0036] Preferably, the GPIO pin described in step six includes a protection diode and pull-up and pull-down resistors.

[0037] The protection diode is used to prevent external voltage input that is too high or too low to protect the chip from damage, and the pull-up and pull-down resistors allow the user to set the default state of the pin to high or low.

[0038] Preferably, the configuration of the GPIO pins described in step six is ​​implemented by programming, and the GPIO pin configuration process includes selecting an output mode, setting a pin function, and controlling the state of the pin by writing code.

[0039] This makes the configuration process of the GPIO pins more reasonable and convenient, and can also well control and supervise the operation of the GPIO pins, ensuring the stability of the entire GPIO pin operation.

[0040] Preferably, the SCK pulse described in step 4 is generated during data transmission, and the frequency of the SCK pulse is twice the sampling frequency multiplied by the number of sampling bits.

[0041] This design ensures the accurate synchronous transmission of data and the accuracy of the data at each sampling point, so the accuracy and stability of the digital audio signal can be guaranteed by setting the correct SCK pulse frequency.

[0042] Preferably, the CS / SS pin operation described in step three includes slave device selection, clock signal synchronization, data transmission and data exchange.

[0043] The CS / SS pin is a signal pin for slave device selection, which is controlled by the master device and is used to select a specific slave device from multiple slave devices for communication. In the SPI communication protocol, the CS / SS pin plays a vital role. When the master device wants to communicate with a slave device, it selects a specific slave device by setting the CS / SS pin to a low level, indicating the start of communication with the slave device.

[0044] Preferably, the MOSI described in step 1 is the host data output and the slave data input, and the MOSI is used for the SPI device to send data.

[0045] The MOSI line is mainly used for SPI devices to send data, that is, the host sends data to the slave through the MOSI line.

[0046] The beneficial effects of the present invention are as follows:

[0047] The present invention realizes a method for implementing GPIO simulation SPI communication on an embedded Linux platform, realizes SPI communication between a touch screen and the platform when the platform hardware SPI resources are insufficient, and can also mount more SPI slave devices on the platform in this way, thereby effectively improving the application scope of the SPI communication and bringing convenience to operators' operation. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 It is a block diagram of the SPI communication process of the present invention. DETAILED DESCRIPTION

[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0050] like Figure 1As shown, an embodiment of the present invention provides a method for implementing a touch screen driver for GPIO simulating SPI communication, comprising the following steps:

[0051] Step 1: Initialize GPIO

[0052] First, you need to configure the GPIO pins to a mode suitable for SPI communication;

[0053] Configure MOSI (Master Out Slave In): Set to output mode;

[0054] Configure MISO (Master In Slave Out): Set to input mode;

[0055] Configure SCK (Serial Clock): Set to output mode;

[0056] Configure CS / SS (Chip Select / Slave Select): Set to output mode and usually keep it high (unselected state);

[0057] Step 2: Prepare data

[0058] As the SPI master device, prepare the data to be sent, which will be sent one by one in byte or bit order;

[0059] Step 3: Select the slave device

[0060] Before starting data transmission, set the CS / SS pin to low to select a specific slave device;

[0061] Step 4: Sending and receiving data

[0062] For each byte of data transmitted, the following sub-steps need to be performed:

[0063] 1. Sending Data

[0064] Set the most significant bit (MSB) of the data to be sent to the MOSI pin, generate an SCK pulse (SCK from low to high, then from high to low), after the falling edge of SCK, shift the data and prepare to send the next bit, repeat this process until all bits have been sent;

[0065] 2. Receive data

[0066] Before the rising edge of SCK, the level of the MISO pin will reflect the bit sent by the slave device. After the falling edge of SCK, the state of the MISO pin is read and saved into the bit of the received data.

[0067] 3. Repeat this process until all bits are received;

[0068] Step 5: Complete data transfer

[0069] When all data has been sent and received, set the CS / SS pin high again to release the slave device;

[0070] Step 6: Delay and Synchronization

[0071] Between setting the GPIO pin and generating the SCK pulse, you may need to insert a delay to ensure data stability. This is because the GPIO operation may be very fast, and the external device may need some time to respond to the signal change. The delay can be implemented by a software delay loop or by using a hardware timer.

[0072] Step 7: Process the received data

[0073] The received data usually needs to be reassembled into bytes according to the SPI bit order, which involves bit shifts and OR operations.

[0074] This paper proposes a method to implement gpio simulation spi communication on embedded Linux platform. When the platform hardware SPI resources are insufficient, the spi communication between the touch screen and the platform can be realized. More spi slave devices can also be mounted on the platform in this way, thereby effectively improving the application scope of the SPI communication and bringing convenience to the operator's operation.

[0075] Among them, the SPI communication in step one supports multiple modes. By configuring different combinations of clock polarity (CPOL) and clock phase (CPHA), different data sampling and shifting timings can be achieved.

[0076] This design ensures the flexibility and compatibility of SPI communication, enables it to adapt to different hardware and software requirements, effectively improves the application scope of the communication, and brings convenience to operators.

[0077] The SPI communication in step one is a full-duplex interface, and data transmission and reception are performed simultaneously when the SPI communication is running.

[0078] This design ensures good stability during SPI communication, while also ensuring that there will be no missing data during transmission, thus ensuring the security of data transmission.

[0079] Among them, the data transmission of the MISO pin in step 4 is performed synchronously, and the MISO pin is a dual-channel communication.

[0080] Such a mechanism ensures the accuracy and efficiency of communication, and the MISO pin plays an important role in the SPI communication process. It allows the master device to receive data from the slave device to achieve the effect of two-way communication.

[0081] The GPIO pin in step six includes a protection diode and pull-up and pull-down resistors.

[0082] The protection diode is used to prevent external voltage input that is too high or too low to protect the chip from damage, and the pull-up and pull-down resistors allow the user to set the default state of the pin to high or low.

[0083] Among them, the configuration of the GPIO pin in step six is ​​implemented by programming, and the GPIO pin configuration process includes selecting the output mode, setting the pin function, and controlling the state of the pin by writing code.

[0084] This makes the configuration process of the GPIO pins more reasonable and convenient, and can also well control and supervise the operation of the GPIO pins, ensuring the stability of the entire GPIO pin operation.

[0085] The SCK pulse in step 4 is generated during data transmission, and the frequency of the SCK pulse is twice the sampling frequency multiplied by the number of sampling bits.

[0086] This design ensures the accurate synchronous transmission of data and the accuracy of the data at each sampling point, so the accuracy and stability of the digital audio signal can be guaranteed by setting the correct SCK pulse frequency.

[0087] Among them, the CS / SS pin operation in step three includes slave device selection, clock signal synchronization, data transmission and data exchange.

[0088] The CS / SS pin is a signal pin for slave device selection, which is controlled by the master device and is used to select a specific slave device from multiple slave devices for communication. In the SPI communication protocol, the CS / SS pin plays a vital role. When the master device wants to communicate with a slave device, it selects a specific slave device by setting the CS / SS pin to a low level, indicating the start of communication with the slave device.

[0089] Among them, MOSI in step 1 is the host data output and slave data input, and MOSI is used for the SPI device to send data.

[0090] The MOSI line is mainly used for SPI devices to send data, that is, the host sends data to the slave through the MOSI line.

[0091] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0092] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for realizing a touch screen driver for GPIO simulating SPI communication, characterized in that: The following steps are involved: Step 1: Initialize GPIO First, you need to configure the GPIO pins to a mode suitable for SPI communication; Configure MOSI (Master Out Slave In): Set to output mode; Configure MISO (Master In Slave Out): Set to input mode; Configure SCK (Serial Clock): Set to output mode; Configure CS / SS (Chip Select / Slave Select): Set to output mode and usually keep it high (unselected state); Step 2: Prepare data As the SPI master device, prepare the data to be sent, which will be sent one by one in byte or bit order; Step 3: Select the slave device Before starting data transmission, set the CS / SS pin to low to select a specific slave device; Step 4: Sending and receiving data For each byte of data transmitted, the following sub-steps need to be performed:

1. Sending Data Set the most significant bit (MSB) of the data to be sent to the MOSI pin, generate an SCK pulse (SCK from low to high, then from high to low), after the falling edge of SCK, shift the data and prepare to send the next bit, repeat this process until all bits have been sent; 2. Receive data Before the rising edge of SCK, the level of the MISO pin will reflect the bit sent by the slave device. After the falling edge of SCK, the state of the MISO pin is read and saved into the bit of the received data.

3. Repeat this process until all bits are received; Step 5: Complete data transfer When all data has been sent and received, set the CS / SS pin high again to release the slave device; Step 6: Delay and Synchronization Between setting the GPIO pin and generating the SCK pulse, you may need to insert a delay to ensure data stability. This is because the GPIO operation may be very fast, and the external device may need some time to respond to the signal change. The delay can be implemented by a software delay loop or by using a hardware timer. Step 7: Process the received data The received data usually needs to be reassembled into bytes according to the SPI bit order, which involves bit shifts and OR operations.

2. A method for realizing touch screen driving of GPIO simulating SPI communication according to claim 1, characterized in that: The SPI communication described in step 1 supports multiple modes. Different data sampling and shifting timings can be achieved by configuring different combinations of clock polarity (CPOL) and clock phase (CPHA).

3. A method for realizing touch screen driving of GPIO simulating SPI communication according to claim 1, characterized in that: The SPI communication described in step 1 is a full-duplex interface, and data transmission and reception are performed simultaneously when the SPI communication is running.

4. A method for realizing touch screen driving of GPIO simulating SPI communication according to claim 1, characterized in that: The data transmission of the MISO pin described in step 4 is performed synchronously, and the MISO pin is a dual-channel communication.

5. A method for driving a touch screen to realize gpio simulation spi communication according to claim 1, characterized in that: The GPIO pin described in step 6 includes a protection diode and pull-up and pull-down resistors.

6. A method for realizing a touch screen driving of GPIO simulating SPI communication according to claim 1, characterized in that: The configuration of the GPIO pins described in step six is ​​achieved through programming, and the GPIO pin configuration process includes selecting an output mode, setting a pin function, and controlling the state of the pin by writing code.

7. A method for driving a touch screen to realize gpio simulation spi communication according to claim 1, characterized in that: The SCK pulse described in step 4 is generated during data transmission, and the frequency of the SCK pulse is twice the sampling frequency multiplied by the number of sampling bits.

8. A method for driving a touch screen to realize GPIO simulating SPI communication according to claim 1, characterized in that: The CS / SS pin operation described in step 3 includes slave device selection, clock signal synchronization, data transmission and data exchange.

9. A method for driving a touch screen to realize gpio simulation spi communication according to claim 1, characterized in that: The MOSI described in step 1 is the host data output and the slave data input, and the MOSI is used for the SPI device to send data.