Lines Matching refs:SPI

1 # SPI  chapter
6 …al Peripheral Interface (SPI) is a serial bus specification used for high-speed, full-duplex, and …
8 SPI works in controller/device mode. Generally, there is one SPI controller that controls one or mo…
9 - SCLK: clock signal output from the SPI controller
10 - MOSI: data output from the SPI controller to a device
11 - MISO: data output from an SPI device to the controller
12 …- Chip select (CS): output from the SPI controller to indicate that data is being sent. It is cont…
16 **Figure 1** Connection between the SPI controller and devices
20 - SPI communication is usually initiated by the controller and is performed as follows:
21 …1. The SPI controller selects a device to communicate on the select line. Only one device can be s…
23 …3. The SPI controller sends data to the device via MOSI, and receives data from the devices via MI…
25 - SPI can work in one of the following modes according to the combination of Clock Polarity (CPOL) …
31 - SPI defines a set of common functions for operating an SPI device, including those for:
32 - Obtaining and releasing an SPI device handle.
33 - Reading or writing data of the specified length from or into an SPI device.
35 - Obtaining and setting SPI device attributes.
38 > Currently, these functions are only applicable in the communication initiated by the SPI controll…
43 **Table 1** SPI driver APIs
47 | SpiOpen | Opens an SPI device handle.|
48 | SpiClose | Closes an SPI device handle.|
51 | SpiTransfer | Transfers SPI data.|
52 | SpiSetCfg | Sets SPI device attributes.|
53 | SpiGetCfg | Obtains SPI device attributes.|
64 The figure below shows the general process of using SPI.
66 **Figure 2** Process of using SPI APIs
68 ![](figures/using-SPI-process.png)
71 ### Opening an SPI Device Handle
73 Before performing SPI communication, call **SpiOpen** to open the SPI device handle. This function …
84 | info | Pointer to the SPI device descriptor.|
87 | Device handle| The operation is successful. The SPI device handle obtained is returned.|
89 For example, open the handle of the SPI device, whose bus number and the CS number are both **0**.
93 struct SpiDevInfo spiDevinfo; /* SPI device descriptor. */
94 DevHandle spiHandle = NULL; /* SPI device handle */
95 spiDevinfo.busNum = 0; /* SPI device bus number. */
96 spiDevinfo.csNum = 0; /* SPI device CS number. */
98 /* Obtain the SPI device handle. */
107 ### Obtaining SPI Device Attributes
109 After obtaining the SPI device handle, you need to configure the device attributes. Before configur…
120 | handle | SPI device handle.|
121 | cfg | Pointer to the SPI device attributes.|
129 struct SpiCfg cfg = {0}; /* SPI configuration. */
130 ret = SpiGetCfg(spiHandle, &cfg); /* Obtain SPI device attributes. */
137 ### Setting SPI Device Attributes
139 After obtaining the SPI device handle, call **SpiSetCfg** to set SPI device attributes.
150 | handle | SPI device handle.|
151 | cfg | Pointer to the SPI device attributes.|
159 struct SpiCfg cfg = {0}; /* SPI configuration. */
164 ret = SpiSetCfg(spiHandle, &cfg); /* Set SPI device attributes. */
171 ### Performing SPI Communication
173 - Write data to an SPI device
175 Call **SpiWrite()** to write data to an SPI device only once.
186 | handle | SPI device handle.|
197 /* Write data of the specified length to an SPI device. */
204 - Read data from an SPI device
206 Call **SpiRead()** to read data from an SPI device only once.
217 | handle | SPI device handle.|
228 /* Read data of the specified length from an SPI device. */
248 | handle | SPI device handle.|
275 ### Closing an SPI Device Handle
277 After the SPI communication, call **SpiClose()** to close the SPI device handle.
290 | handle | SPI device handle.|
294 SpiClose(spiHandle); /* Close the SPI device handle. */
300 … to obtain an SPI device handle, set device attributes, and then read or write data from or into t…
309 struct SpiCfg cfg; /* SPI device configuration. */
310 struct SpiDevInfo spiDevinfo; /* SPI device descriptor. */
311 DevHandle spiHandle = NULL; /* SPI device handle. */
317 spiDevinfo.busNum = 0; /* SPI device bus number. */
318 spiDevinfo.csNum = 0; /* SPI device CS number. */
319 spiHandle = SpiOpen(&spiDevinfo); /* Open the SPI device handle based on spiDevinfo. */
324 /* Obtain SPI attributes. */
332 /* Set SPI attributes. */
338 /* Write data of the specified length to an SPI device. */
344 /* Read data of the specified length from an SPI device. */
363 /* Close the SPI device handle. */