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
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
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-
= 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
;
......
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
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
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
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
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:
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
U8 spi1_readwritebyte (U8 txdata) {U8 retry=0; while (Spi_i2s_getflagstatus (SPI1, spi_i2s_flag_txe) = = RESET)//Check the specified SPI labelLog bit set or not: Send cache null flag bit {retry++;
if (retry>200) return 0; } spi_i2s_senddata (SPI1, TxData);
Send a data retry=0 via peripheral Spix;
while (Spi_i2s_getflagstatus (SPI1, spi_i2s_flag_rxne) = = RESET)//Check the specified SPI flag bit setti
SPI, I²C, serial port, I believe if you are engaged in embedded development, will be used to the three communication protocols, serial port words because and baud rate related, so the general CPU or MCU will only be equipped with two or three serial port, and the transmission of data, the SPI and i²c use will be more, A blog was found below. Turn around,
1, the UART is two lines, one sends a r
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 spee
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-tim
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
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
registers, in the main device shift pulse, data by bit, high in front, low after, for full-duplex communication, data transmission speed overall than the I2C bus faster, the speed can reach the Mbps level.
SPI has four working modes , depending on clock polarity and clock phase. Clock polarity has high and low pole
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
The 4 operating modes of the SPI bus 0 to 4 Modesspi interface is the full name of "Serial peripheral Interface", meaning the serial peripheral interface, Motorola first defined on its MC68HCXX series processor. The SPI interface is used primarily in eeprom,flash, real-time clocks, ad converters, and digital signal processors and digital signal decoders.The
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.