receiving buffer immediately. set the full flag (BF) and interrupt flag (sspif) of the master receiving buffer to "1 ". After the master CPU detects the full or interrupt mark position 1 of the master receiving buffer, it can read the data in the receiving buffer. Similarly, after the CPU detects that the receiving buffer is full or the interrupt flag is 1, the data in the receiving buffer can be read to complete the communication process. Here, dspic30f6014 is set as the master controller, and
!/*****************************************************************************************************/The code for the SPI Universal Interface layer is concentrated in:/drivers/spi/spi.c.Initialization of the SPI device model
Typically, depending on how the Linux device model is organized, various devices are hung on the appropriate
;
......
Pd.num_cs = Num_cs;
PD.SRC_CLK_NR = SRC_CLK_NR;
Pd.cfg_gpio = (cfg_gpio)? Cfg_gpio:s3c64xx_spi0_cfg_gpio;
......
S3c_set_platdata (PD, sizeof (PD), s3c64xx_device_spi0);
The above function is to specify the GPIO configuration that the controller uses, the number of slices of pins and the clock configuration. This information is used in the subsequent controller driver.
registering the platform_driver of the SPI Controller
I
= Src_clk_nr;pd.cfg_gpio = (cfg_gpio)? Cfg_gpio:s3c64xx_spi0_cfg_gpio; ... s3c_set_platdata (PD, sizeof (PD), s3c64xx_device_spi0);}The above functions mainly specify the GPIO configuration used by the controller, the number of pin pins and the clock configuration. This information is to be used in the controller driver behind.Register the SPI Controller Platform_driver
In the previous section, we registered the
SPI, is the abbreviation of English serial Peripheral interface, as the name implies is the serial peripheral device interface. SPI, is a high-speed, full-duplex, synchronous communication bus, and on the chip's pin only occupies four lines, saving the chip pin, while the layout of the PCB space saving, convenient, it is for this simple and easy to use features,
pending spi_message structures under Master, and the worker thread will process each of these message requests on a first-in, one-out basis, after each message transfer is complete, corresponding to the Spi_ The complete callback function of the message structure is called to notify the Protocol driver to prepare the next frame of data. This is the spi_message of the queue. When a worker thread wakes up, the relationship between Spi_master, Spi_message, and spi_transfer can be used to describe:
MCU simulation SPI interface-deep understanding of SPI bus protocol SPI (serial peripheral interfacer serial peripheral interface) is a synchronous serial communication interface launched by Motorola, the serial connection between the microprocessor compaction controller and the peripheral extended chip has developed i
below it, and the worker threads will process the message requests one at a time according to the FIFO principle, and after each message transfer, the corresponding SPI_ The complete callback function of the message structure is invoked to notify the Protocol driver of preparing the next frame of data. This is the queue of spi_message. When a worker thread wakes up, the relationship between Spi_master, Spi_message, and Spi_transfer can be described in the following illustration:
queues and
I still remember that the first time I used the SPI device was my junior summer vacation. At that time, I bought a wireless module with my teammates and used a single-chip microcomputer for wireless transmission, but the code was not written by myself, although this function was implemented, I still had no idea about SPI at the time. Senior, I felt ashamed to ask how to use
The last 2 weeks have been debugging IIC and SPI bus equipment, here record 2 kinds of bus, in case of forgetting.
One IIC Bus
The abbreviation of I2c--inter-ic serial Bus is the serial transmission bus between chips introduced by
About I2C and SPI bus protocols
Iicvs SPI
Currently, in the low-end digital communication application field, we can see IIC (Inter-Integrated Circuit) and SPI (serial peripheral interface) everywhere. The reason is that these two communication protocols are very suitable for close-range and low-speed chip communication
that the initial level of the clock signal is high. In addition, we use Cpha to indicate that the clock along the sampled data, Cpha to 0 means that the first clock changes along the sampled data, while the Cpha of 1 indicates that the second clock changes along the edge to sample data. The kernel uses a combination of Cpol and cpha to represent the working mode that the current SPI requires:
Cpol=0,cpha=1 Mode 0
Cpol=0,cpha=1 Mode 1
features are: can send and receive serial data at the same time, can be used as a host or slave, provide frequency programmable clock, send end interrupt sign, write conflict protection, bus competition protection.In this chapter, we will use the SPI of the STM32 to read the external SPI FLASH chip (w25q64) to achieve a function similar to the previous section.W
, the difference is on the electrical signal line:The SPI bus consists of three signal lines: Serial clock (SCLK), serial data output (SDO), serial data input (SDI). The SPI bus enables multiple SPI devices to be connected to each other. The
Now that we know the protocol, we can start to look at the SPI driver code in Linux kenerl. There are many struct in the code, so let's take a look at the main struct first, in this way, we can better understand the driver. Mainly include/Linux/SPI. h
The first is the communication interface between the SPI host and the slave, that is, the
software architecture SPI Controller Driver
The SPI Controller does not care about the specific functions of the device, it is only responsible for the upper layer protocol drive prepared data according to the SPI bus timing requirements sent to the SPI device, while
Principles, differences and Applications of SPI, I2C, and UART Serial Bus
1. UART is a two-line interface. One transmission and one receiving interface can communicate with each other in full duplex mode, and the number of lines is relatively small. Data is transmitted asynchronously, with strict timing requirements on both parties, and the communication speed is not fast. It is used most frequen
is a low level, and 1 indicates that the initial level of the clock signal is a high level. In addition, we use Cpha to indicate that at that clock along the sampled data, Cpha 0 indicates that the first clock changes along the sampling data, while the Cpha 1 means to sample the data along the second clock change. The kernel uses a combination of Cpol and cpha to represent the working mode that the current SPI requires: Cpol=0,cpha=1 mode 0 cpol=0
is a low level, and 1 indicates that the initial level of the clock signal is a high level. In addition, we use Cpha to indicate that at that clock along the sampled data, Cpha 0 indicates that the first clock changes along the sampling data, while the Cpha 1 means to sample the data along the second clock change. The kernel uses a combination of Cpol and cpha to represent the working mode that the current SPI requires: Cpol=0,cpha=1 mode 0 cpol=0
The abbreviation for the Serial Peripheral Interface (Serial peripheral interface,spi). is a high-speed, full-duplex, synchronous communication bus that occupies only four wires on the chip's pins. Motorola is first defined on its MC68HCXX series processors. The SPI interface is used primarily in eeprom,flash, real-time clocks, ad converters, and digital signal p
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.