1 /* -----------------------------------------------------------------------------
2 * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
4 * $Date: 2. January 2014
7 * Project: SPI Driver API
8 * -------------------------------------------------------------------------- */
12 \defgroup spi_interface_gr SPI Interface
13 \brief Driver API for SPI Bus Peripheral (%Driver_SPI.h)
15 The <b>Serial Peripheral Interface Bus</b> (SPI) implements a synchronous serial bus for data exchange. In microcontroller (MCU) applications,
16 the interface is often used to connect peripheral components at board (PCB) level. SPI devices can operate as Master (SCLK and SS are outputs) or
17 Slave (SCLK and SS are inputs). Wikipedia offers more information about
18 the <a href="http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus" target="_blank"><b>Serial Peripheral Interface Bus</b></a>.
22 The SPI Driver API defines a <b>SPI</b> interface for middleware components. The SPI Driver supports multiple
23 slaves, but if only one slave is connected, then the Slave Select signal can be omitted.
26 \image html SPI_Master1Slaves.png "SPI Master connected to a single slave"
30 \image html SPI_Master3Slaves.png "SPI Master connected to 3 slaves"
32 The SPI Driver functions control the following SPI signal lines.
34 Signal | Name | Description
35 -------|-------------------------------------|------------------------------------------------------------------------------
36 SS | Slave Select (active low) | Selects the slave. This signal can be part of the SPI peripheral or implemented using a GPIO pin.
37 MOSI | Master Out, Slave In | MOSI output of the Master connects to MOSI input of the Slave.
38 SCLK | Serial Clock | Serial clock output from Master. Controls the transfer speed and when data are sent and read.
39 MISO | Master In, Slave Out | MISO input of the Master connects to MISO output of the Slave.
44 The following header files define the Application Programming Interface (API) for the SPI interface:
45 - \b %Driver_SPI.h : Driver API for SPI Bus Peripheral
47 The driver implementation is a typical part of the Device Family Pack (DFP) that supports the
48 peripherals of the microcontroller family.
51 <b>Driver Functions</b>
53 The driver functions are published in the access struct as explained in \ref DriverFunctions
54 - \ref ARM_DRIVER_SPI : access struct for SPI driver functions
59 The following example code shows the usage of the SPI interface.
68 \struct ARM_DRIVER_SPI
70 The functions of the SPI driver are accessed by function pointers exposed by this structure.
71 Refer to \ref DriverFunctions for overview information.
73 Each instance of a SPI interface provides such an access structure.
74 The instance is identified by a postfix number in the symbol name of the access structure, for example:
75 - \b Driver_SPI0 is the name of the access struct of the first instance (no. 0).
76 - \b Driver_SPI1 is the name of the access struct of the second instance (no. 1).
78 A middleware configuration setting allows connecting the middleware to a specific driver instance \b %Driver_SPI<i>n</i>.
79 The default is \token{0}, which connects a middleware to the first instance of a driver.
80 **************************************************************************************************************************/
83 \struct ARM_SPI_CAPABILITIES
85 A SPI driver can be implemented with different capabilities.
86 The data fields of this structure encode the capabilities implemented by this driver.
89 - \ref ARM_SPI_GetCapabilities
90 **************************************************************************************************************************/
93 \struct ARM_SPI_STATUS
95 Structure with information about the status of the SPI. The data fields encode busy flag and error flags.
98 - \ref ARM_SPI_GetStatus
99 *****************************************************************************************************************/
103 \typedef ARM_SPI_SignalEvent_t
105 Provides the typedef for the callback function \ref ARM_SPI_SignalEvent.
107 <b>Parameter for:</b>
108 - \ref ARM_SPI_Initialize
109 *******************************************************************************************************************/
112 \defgroup spi_execution_status Status Error Codes
113 \ingroup common_drv_gr
114 \brief Negative values indicate errors (SPI has specific codes in addition to common \ref execution_status).
116 The SPI driver has additional status error codes that are listed below.
117 Note that the SPI driver also returns the comon \ref execution_status.
120 \def ARM_SPI_ERROR_MODE
121 The \b mode requested with the function \ref ARM_SPI_Control is not supported by this driver.
123 \def ARM_SPI_ERROR_FRAME_FORMAT
124 The <b>frame format</b> requested with the function \ref ARM_SPI_Control is not supported by this driver.
126 \def ARM_SPI_ERROR_DATA_BITS
127 The number of <b>data bits</b> requested with the function \ref ARM_SPI_Control is not supported by this driver.
129 \def ARM_SPI_ERROR_BIT_ORDER
130 The <b>bit order</b> requested with the function \ref ARM_SPI_Control is not supported by this driver.
132 \def ARM_SPI_ERROR_SS_MODE
133 The <b>slave select mode</b> requested with the function \ref ARM_SPI_Control is not supported by this driver.
138 \defgroup SPI_events SPI Events
139 \ingroup spi_interface_gr
140 \brief The SPI driver generates call back events that are notified via the function \ref ARM_SPI_SignalEvent.
142 This section provides the event values for the \ref ARM_SPI_SignalEvent callback function.
144 The following call back notification events are generated:
146 \def ARM_SPI_EVENT_TRANSFER_COMPLETE
147 \def ARM_SPI_EVENT_DATA_LOST
148 \def ARM_SPI_EVENT_MODE_FAULT
156 ARM_DRIVER_VERSION ARM_SPI_GetVersion (void) {
160 \fn ARM_DRIVER_VERSION ARM_SPI_GetVersion (void)
162 The function \b ARM_SPI_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
163 - API version is the version of the CMSIS-Driver specification used to implement this driver.
164 - Driver version is source code version of the actual driver implementation.
168 extern ARM_DRIVER_SPI Driver_SPI0;
169 ARM_DRIVER_SPI *drv_info;
171 void setup_spi (void) {
172 ARM_DRIVER_VERSION version;
174 drv_info = &Driver_SPI0;
175 version = drv_info->GetVersion ();
176 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
182 **************************************************************************************************************************/
184 ARM_SPI_CAPABILITIES ARM_SPI_GetCapabilities (void) {
188 \fn ARM_SPI_CAPABILITIES ARM_SPI_GetCapabilities (void)
190 The function \b ARM_SPI_GetCapabilities returns information about the capabilities in this driver implementation.
191 The data fields of the structure \ref ARM_SPI_CAPABILITIES encode various capabilities, for example
196 extern ARM_DRIVER_SPI Driver_SPI0;
197 ARM_DRIVER_SPI *drv_info;
199 void read_capabilities (void) {
200 ARM_SPI_CAPABILITIES drv_capabilities;
202 drv_info = &Driver_SPI0;
203 drv_capabilities = drv_info->GetCapabilities ();
204 // interrogate capabilities
209 **************************************************************************************************************************/
211 int32_t ARM_SPI_Initialize (ARM_SPI_SignalEvent_t cb_event) {
212 return ARM_DRIVER_OK;
215 \fn int32_t ARM_SPI_Initialize (ARM_SPI_SignalEvent_t cb_event)
217 The function \b ARM_SPI_Initialize initializes the SPI interface.
219 The parameter \em cb_event is a pointer to the \ref ARM_SPI_SignalEvent callback function; use a NULL pointer
220 when no callback signals are required.
222 The function is called when the middleware component starts operation and performs the following:
223 - Initializes the resources needed for the SPI interface.
224 - Registers the \ref ARM_SPI_SignalEvent callback function.
228 - see \ref spi_interface_gr - Driver Functions
230 **************************************************************************************************************************/
232 int32_t ARM_SPI_Uninitialize (void) {
233 return ARM_DRIVER_OK;
236 \fn int32_t ARM_SPI_Uninitialize (void)
238 The function \b ARM_SPI_Uninitialize de-initializes the resources of SPI interface.
240 It is called when the middleware component stops operation and releases the software resources used by the interface.
241 **************************************************************************************************************************/
243 int32_t ARM_SPI_PowerControl (ARM_POWER_STATE state) {
244 return ARM_DRIVER_OK;
247 \fn int32_t ARM_SPI_PowerControl (ARM_POWER_STATE state)
249 The function \b ARM_SPI_PowerControl controls the power modes of the SPI interface.
251 The parameter \em state sets the operation and can have the following values:
252 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA.
253 Can be called multiple times. If the peripheral is already in this mode the function performs
254 no operation and returns with \ref ARM_DRIVER_OK.
255 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
256 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
258 Refer to \ref CallSequence for more information.
259 **************************************************************************************************************************/
261 int32_t ARM_SPI_Send (const void *data, uint32_t num) {
262 return ARM_DRIVER_OK;
265 \fn int32_t ARM_SPI_Send (const void *data, uint32_t num)
267 This function \b ARM_SPI_Send is used to send data to the SPI transmitter (received data is ignored).
269 The parameter \em data specifies the data buffer. \n
270 The parameter \em num specifies the number of items to send. \n
271 The item size is defined by the data type, which depends on the configured number of data bits.
274 - \em uint8_t when configured for 1..8 data bits
275 - \em uint16_t when configured for 9..16 data bits
276 - \em uint32_t when configured for 17..32 data bits
278 Calling the function \b ARM_SPI_Send only starts the send operation.
279 When in slave mode, the operation is only registered and started when the master starts the transfer.
280 The function is non-blocking and returns as soon as the driver has started the operation
281 (driver typically configures DMA or the interrupt system for continuous transfer).
282 During the operation it is not allowed to call this function or any other data transfer function again.
283 Also the data buffer must stay allocated and the contents of unsent data must not be modified.
284 When send operation is completed (requested number of items sent), the \ref ARM_SPI_EVENT_TRANSFER_COMPLETE event is generated.
285 Progress of send operation can also be monitored by reading the number of items already sent by calling \ref ARM_SPI_GetDataCount.
287 Status of the transmitter can also be monitored by calling the \ref ARM_SPI_GetStatus and checking the \em busy data field,
288 which indicates if transmission is still in progress or pending.
290 When in master mode and configured to monitor slave select and the slave select gets deactivated during transfer,
291 then the SPI mode changes to inactive and the \ref ARM_SPI_EVENT_MODE_FAULT event is generated (instead of \ref ARM_SPI_EVENT_TRANSFER_COMPLETE).
293 When in slave mode but send/receive/transfer operation is not started and data is sent/requested by the master,
294 then the \ref ARM_SPI_EVENT_DATA_LOST event is generated.
296 Send operation can be aborted by calling \ref ARM_SPI_Control with \ref ARM_SPI_ABORT_TRANSFER as the control parameter.
297 **************************************************************************************************************************/
299 int32_t ARM_SPI_Receive (void *data, uint32_t num) {
300 return ARM_DRIVER_OK;
303 \fn int32_t ARM_SPI_Receive (void *data, uint32_t num)
305 The function \b ARM_SPI_Receive is used to receive data
306 (transmits the default value as specified by \ref ARM_SPI_Control with \ref ARM_SPI_SET_DEFAULT_TX_VALUE as control parameter).
308 The parameter \em data specifies the data buffer. \n
309 The parameter \em num specifies the number of items to receive. \n
310 The item size is defined by the data type, which depends on the configured number of data bits.
313 - \em uint8_t when configured for 1..8 data bits
314 - \em uint16_t when configured for 9..16 data bits
315 - \em uint32_t when configured for 17..32 data bits
317 Calling the function \b ARM_SPI_Receive only starts the receive operation.
318 The function is non-blocking and returns as soon as the driver has started the operation
319 (driver typically configures DMA or the interrupt system for continuous transfer).
320 When in slave mode, the operation is only registered and started when the master starts the transfer.
321 During the operation it is not allowed to call this function or any other data transfer function again. Also the data buffer must stay allocated.
322 When receive operation is completed (requested number of items received), the \ref ARM_SPI_EVENT_TRANSFER_COMPLETE event is generated.
323 Progress of receive operation can also be monitored by reading the number of items already received by calling \ref ARM_SPI_GetDataCount.
325 Status of the receiver can also be monitored by calling the \ref ARM_SPI_GetStatus and checking the \em busy data field,
326 which indicates if reception is still in progress or pending.
328 When in master mode and configured to monitor slave select and the slave select gets deactivated during transfer,
329 then the SPI mode changes to inactive and the \ref ARM_SPI_EVENT_MODE_FAULT event is generated (instead of \ref ARM_SPI_EVENT_TRANSFER_COMPLETE).
331 When in slave mode but send/receive/transfer operation is not started and data is sent/requested by the master,
332 then the \ref ARM_SPI_EVENT_DATA_LOST event is generated.
334 Receive operation can be aborted by calling \ref ARM_SPI_Control with \ref ARM_SPI_ABORT_TRANSFER as the control parameter.
335 **************************************************************************************************************************/
337 int32_t ARM_SPI_Transfer (const void *data_out, void *data_in, uint32_t num) {
338 return ARM_DRIVER_OK;
341 \fn int32_t ARM_SPI_Transfer (const void *data_out, void *data_in, uint32_t num)
343 The function \b ARM_SPI_Transfer transfers data via SPI. It synchronously sends data to the SPI transmitter and receives data from the SPI receiver.
345 The parameter \em data_out is a pointer to the buffer with data to send. \n
346 The parameter \em data_in is a pointer to the buffer which receives data. \n
347 The parameter \em num specifies the number of items to transfer. \n
348 The item size is defined by the data type which depends on the configured number of data bits.
351 - \em uint8_t when configured for 1..8 data bits
352 - \em uint16_t when configured for 9..16 data bits
353 - \em uint32_t when configured for 17..32 data bits
355 Calling the function \b ARM_SPI_Transfer only starts the transfer operation.
356 The function is non-blocking and returns as soon as the driver has started the operation
357 (driver typically configures DMA or the interrupt system for continuous transfer).
358 When in slave mode, the operation is only registered and started when the master starts the transfer.
359 During the operation it is not allowed to call this function or any other data transfer function again.
360 Also the data buffers must stay allocated and the contents of unsent data must not be modified.
361 When transfer operation is completed (requested number of items transferred), the \ref ARM_SPI_EVENT_TRANSFER_COMPLETE event is generated.
362 Progress of transfer operation can also be monitored by reading the number of items already transferred by calling \ref ARM_SPI_GetDataCount.
364 Status of the transmitter and receiver can also be monitored by calling the \ref ARM_SPI_GetStatus and checking the \em busy flag.
366 When in master mode and configured to monitor slave select and the slave select gets deactivated during transfer,
367 then the SPI mode changes to inactive and the \ref ARM_SPI_EVENT_MODE_FAULT event is generated (instead of \ref ARM_SPI_EVENT_TRANSFER_COMPLETE).
369 When in slave mode but send/receive/transfer operation is not started and data is sent/requested by the master,
370 then the \ref ARM_SPI_EVENT_DATA_LOST event is generated.
372 Transfer operation can also be aborted by calling \ref ARM_SPI_Control with \ref ARM_SPI_ABORT_TRANSFER as the control parameter.
373 **************************************************************************************************************************/
375 uint32_t ARM_SPI_GetDataCount (void) {
379 \fn uint32_t ARM_SPI_GetDataCount (void)
381 The function \b ARM_SPI_GetDataCount returns the number of currently transferred data items
382 during \ref ARM_SPI_Send, \ref ARM_SPI_Receive and \ref ARM_SPI_Transfer operation.
383 *****************************************************************************************************************/
385 int32_t ARM_SPI_Control (uint32_t control, uint32_t arg) {
386 return ARM_DRIVER_OK;
389 \fn int32_t ARM_SPI_Control (uint32_t control, uint32_t arg)
391 The function \b ARM_SPI_Control controls the SPI interface settings and executes various operations.
393 The parameter \em control is a bit mask that specifies various operations.
394 - Controls form different categories can be ORed.
395 - If one control is omitted, then the default value of that category is used.
396 - Miscellaneous controls cannot be combined.
398 The parameter \em arg provides (depending on the parameter \em control) additional information, for example the Bus Speed.
401 <table class="cmtable" summary="">
402 <tr><th> Parameter \em control </th>
403 <th style="text-align:right"> Bit </th>
407 <tr><td> \ref ARM_SPI_MODE_INACTIVE </td>
408 <td rowspan="5" style="text-align:right"> 0..7 </td>
409 <td rowspan="5"> \anchor spi_mode_tab Mode Controls </td>
410 <td> Set SPI to inactive.
412 <tr><td> \ref ARM_SPI_MODE_MASTER </td>
413 <td> Set the SPI Master (Output on MOSI, and the Input on MISO); \em arg = Bus Speed in \token{bps}
415 <tr><td> \ref ARM_SPI_MODE_MASTER_SIMPLEX </td>
416 <td> Set the SPI Master (Output and Input on MOSI); \em arg = Bus Speed in \token{bps}
418 <tr><td> \ref ARM_SPI_MODE_SLAVE </td>
419 <td> Set the SPI Slave (Output on MISO, and the Input on MOSI)
421 <tr><td> \ref ARM_SPI_MODE_SLAVE_SIMPLEX </td>
422 <td> Set the SPI Slave (Output and Input on MISO)
424 <tr><td> \ref ARM_SPI_CPOL0_CPHA0 (default) </td>
425 <td rowspan="6" style="text-align:right"> 8..11 </td>
426 <td rowspan="6"> Clock Polarity <br> (Frame Format) </td><td> CPOL=\token{0} and CPHA=\token{0}: Clock Polarity 0, Clock Phase 0 </td>
428 <tr><td> \ref ARM_SPI_CPOL0_CPHA1 </td>
429 <td> CPOL=\token{0} and CPHA=\token{1}: Clock Polarity 0, Clock Phase 1
431 <tr><td> \ref ARM_SPI_CPOL1_CPHA0 </td>
432 <td> CPOL=\token{1} and CPHA=\token{0}: Clock Polarity 1, Clock Phase 0
434 <tr><td> \ref ARM_SPI_CPOL1_CPHA1 </td>
435 <td> CPOL=\token{1} and CPHA=\token{1}: Clock Polarity 1, Clock Phase 1
437 <tr><td> \ref ARM_SPI_TI_SSI </td>
438 <td> Specifies that the frame format corresponds to the Texas Instruments Frame Format
440 <tr><td> \ref ARM_SPI_MICROWIRE </td>
441 <td> Specifies that the frame format corresponds to the National Microwire Frame Format
443 <tr><td> \ref ARM_SPI_DATA_BITS(n) </td>
444 <td style="text-align:right"> 12..17 </td>
446 <td> Set the number of bits per SPI frame; range for \em n = \token{1..32}.
447 This is the minimum required parameter.
449 <tr><td> \ref ARM_SPI_MSB_LSB (default) </td>
450 <td rowspan="2" style="text-align:right"> 18 </td>
451 <td rowspan="2"> Bit Order </td>
452 <td> Set the bit order from MSB to LSB
454 <tr><td> \ref ARM_SPI_LSB_MSB </td>
455 <td> Set the bit order from LSB to MSB
457 <tr><td nowrap>\ref ARM_SPI_SS_MASTER_UNUSED (default) </td>
458 <td rowspan="6" style="text-align:right"> 19..21 </td>
459 <td rowspan="6"> Slave Select
461 <div style="min-height:200px"> </div>
462 Must be used with the corresponding master or slave controls from category <a href="#spi_mode_tab"><b>Mode Controls</b></a>.
463 <div style="min-height:200px"> </div>
467 <td>Set the Slave Select mode for the master to <b>Not used</b>. Used with Mode Control ARM_SPI_MODE_MASTER.
468 Master does not drive or monitor the SS line. For example, when connecting to a single slave,
469 which has the SS line connected to a fixed low level.
471 <tr><td>\ref ARM_SPI_SS_MASTER_SW</td>
472 <td>Set the Slave Select mode for the master to <b>Software controlled</b>. Used with Mode Control ARM_SPI_MODE_MASTER.
473 The Slave Select line is configured as output and controlled via the Miscellaneous Control \ref ARM_SPI_CONTROL_SS.
474 By default, the line it is not active (high), and is not affected by transfer-, send-, or receive functions.
476 <tr><td>\ref ARM_SPI_SS_MASTER_HW_OUTPUT</td>
477 <td>Set the Slave Select mode for the master to <b>Hardware controlled Output</b>. Used with Mode Control ARM_SPI_MODE_MASTER.
478 The Slave Select line is configured as output and controlled by hardware.
479 The line gets activated or deactivated automatically by the hardware for transfers and is not controlled by the Miscellaneous Control \ref ARM_SPI_CONTROL_SS.
480 When exactly the line is activated or deactivated is hardware dependent. Typically, the hardware will activate the line before starting the transfer
481 and deactivate it after the transfer completes. Some hardware will leave the line activated until the SPI stays master.
482 \note Some devices require that the SS signal is strictly defined regarding transfers. Refer to the documentaiton of your device.
485 <td>\ref ARM_SPI_SS_MASTER_HW_INPUT</td>
486 <td>Set the Slave Select mode for the master to <b>Hardware monitored Input</b>. Used with Mode Control ARM_SPI_MODE_MASTER.
487 Used in multi-master configuration where a master does not drive the Slave Select when driving the bus, but rather monitors it.
488 When another master activates this line, the active master backs off. This is called Mode Fault. Slave Select is configured as input
489 and hardware only monitors the line. When the line is deactivated externally while we are master,
490 it presents a Mode Fault (\ref ARM_SPI_EVENT_MODE_FAULT) and the SPI switches to inactive mode.
492 <tr><td>\ref ARM_SPI_SS_SLAVE_HW (default)</td>
493 <td>Set the Slave Select mode for the slave to <b>Hardware monitored</b>. Used with Mode Control ARM_SPI_MODE_SLAVE.
494 Hardware monitors the Slave Select line and accepts transfers only when the line is active. Transfers are ignored while the Slave Select line is inactive.
496 <tr><td>\ref ARM_SPI_SS_SLAVE_SW</td>
497 <td>Set the Slave Select mode for the slave to <b>Software controlled</b>. Used with Mode Control ARM_SPI_MODE_SLAVE.
498 Used only when the Slave Select line is not used. For example, when a single master and slave are connected in the system
499 then the Slave Select line is not needed. Software controls if the slave is responding or not (by default it is not responding).
500 Software enables or disables transfers by using the Miscellaneous Control \ref ARM_SPI_CONTROL_SS.
502 <tr><td> \ref ARM_SPI_SET_BUS_SPEED </td>
503 <td rowspan="5" style="text-align:right"> 0..21 </td>
504 <td rowspan="5"> Miscellaneous Controls <br>(cannot be ORed)</td>
505 <td>Set the bus speed; \em arg= Bus Speed in \token{bps}
507 <tr><td> \ref ARM_SPI_GET_BUS_SPEED </td>
508 <td> Get the bus speed; Retrun values >= \token{0} reperesent the bus speed in \token{bps}. Negative values are \ref spi_execution_status.
510 <tr><td> \ref ARM_SPI_SET_DEFAULT_TX_VALUE </td>
511 <td> Set the default transmission value; the parameter \em arg sets the value
513 <tr><td> \ref ARM_SPI_CONTROL_SS </td>
514 <td> Control the Slave Select signal (SS); the values for the parameter \em arg are: \token{ARM_SPI_SS_INACTIVE; ARM_SPI_SS_ACTIVE}
516 <tr><td> \ref ARM_SPI_ABORT_TRANSFER </td>
517 <td> Abort the current data transfer
526 extern ARM_DRIVER_SPI Driver_SPI0;
528 // configure: SPI master | clock polarity=1, clock phase=1 | bits per frame=16 | bus speed : 1000000
529 status = Driver_SPI0.Control(ARM_SPI_MODE_MASTER |
530 ARM_SPI_CPOL1_CPHA1 |
531 ARM_SPI_DATA_BITS(16), 1000000);
533 *****************************************************************************************************************/
535 ARM_SPI_STATUS ARM_SPI_GetStatus (void) {
539 \fn ARM_SPI_STATUS ARM_SPI_GetStatus (void)
541 The function \b ARM_SPI_GetStatus returns the current SPI interface status.
542 *****************************************************************************************************************/
544 void ARM_SPI_SignalEvent (uint32_t event) {
548 \fn void ARM_SPI_SignalEvent (uint32_t event)
550 The function \b ARM_SPI_SignalEvent is a callback function registered by the function \ref ARM_SPI_Initialize.
552 The parameter \em event indicates one or more events that occurred during driver operation.
553 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
555 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the
556 data fields of the structure \ref ARM_SPI_CAPABILITIES, which can be retrieved with the function \ref ARM_SPI_GetCapabilities.
558 The following events can be generated:
560 <table class="cmtable" summary="">
562 <th> Parameter \em event </th><th> Bit </th><th> Description </th>
563 <th> supported when ARM_SPI_CAPABILITIES </th>
566 <td> \ref ARM_SPI_EVENT_TRANSFER_COMPLETE </td><td> 0 </td><td> Occurs after call to \ref ARM_SPI_Send, \ref ARM_SPI_Receive,
567 or \ref ARM_SPI_Transfer
568 to indicate that all the data has been transferred.
569 The driver is ready for the next transfer operation. </td>
570 <td> <i>allways supported</i> </td>
573 <td> \ref ARM_SPI_EVENT_DATA_LOST </td><td> 1 </td><td> Occurs in slave mode when data is requested/sent by master
574 but send/receive/transfer operation has not been started and
575 indicates that data is lost. Occurs also in master mode when
576 driver cannot transfer data fast enough. </td>
577 <td> <i>allways supported</i> </td>
580 <td> \ref ARM_SPI_EVENT_MODE_FAULT </td><td> 2 </td><td> Occurs in master mode when Slave Select is deactivated and
581 indicates Master Mode Fault.
582 The driver is ready for the next transfer operation. </td>
583 <td> data field \em event_mode_fault = \token{1} </td>
586 **************************************************************************************************************************/
590 \defgroup SPI_control SPI Control Codes
591 \ingroup spi_interface_gr
592 \brief Many parameters of the SPI driver are configured using the \ref ARM_SPI_Control function.
595 The various SPI control codes define:
597 - \ref spi_mode_ctrls specifies SPI mode
598 - \ref spi_frame_format_ctrls defines the frame format
599 - \ref spi_data_bits_ctrls defines the number of data bits
600 - \ref spi_bit_order_ctrls defines the bit order
601 - \ref spi_slave_select_mode_ctrls specifies slave select mode
602 - \ref spi_misc_ctrls specifies additional miscellaneous controls
604 Refer to the \ref ARM_SPI_Control function for further details.
608 \defgroup spi_mode_ctrls SPI Mode Controls
610 \brief Specifies SPI mode.
613 \def ARM_SPI_MODE_INACTIVE
615 \def ARM_SPI_MODE_MASTER
617 \def ARM_SPI_MODE_SLAVE
619 \def ARM_SPI_MODE_MASTER_SIMPLEX
621 \def ARM_SPI_MODE_SLAVE_SIMPLEX
627 \defgroup spi_frame_format_ctrls SPI Frame Format
629 \brief Defines the frame format.
632 \def ARM_SPI_CPOL0_CPHA0
634 \def ARM_SPI_CPOL0_CPHA1
636 \def ARM_SPI_CPOL1_CPHA0
638 \def ARM_SPI_CPOL1_CPHA1
642 \def ARM_SPI_MICROWIRE
648 \defgroup spi_data_bits_ctrls SPI Data Bits
650 \brief Defines the number of data bits.
653 \def ARM_SPI_DATA_BITS(n)
659 \defgroup spi_bit_order_ctrls SPI Bit Order
661 \brief Defines the bit order.
672 \defgroup spi_slave_select_mode_ctrls SPI Slave Select Mode
674 \brief Specifies SPI slave select mode.
676 \b SPI \b Slave \b Select \b Mode configures the behavior of the \b Slave \b Select \b (SS) signal. The configuration is
677 separate for \b Master (ARM_SPI_SS_MASTER_*) and for \b Slave (\ref ARM_SPI_SS_SLAVE_HW, \ref ARM_SPI_SS_SLAVE_SW). The
678 active configuration depends on the current state (Master/Slave).
681 \def ARM_SPI_SS_MASTER_UNUSED
682 An SPI master does not drive or monitor the SS line. For example, when connecting to a single slave, the SS line can be connected
683 to a fixed low level.
685 \def ARM_SPI_SS_MASTER_SW
686 SS is configured as an output and controlled via \ref ARM_SPI_Control (\ref ARM_SPI_CONTROL_SS). By default, it is not active
687 (high). It is activated (low) by \ref ARM_SPI_Control (\ref ARM_SPI_CONTROL_SS, \ref ARM_SPI_SS_ACTIVE) and deactivated by
688 \ref ARM_SPI_Control (\ref ARM_SPI_CONTROL_SS, \ref ARM_SPI_SS_INACTIVE). It is not affected by transfer/send/receive
691 \def ARM_SPI_SS_MASTER_HW_OUTPUT
692 Here, SS is configured as an output. It will be automatically activated/deactivated for the transfers by hardware (not
693 controlled by \ref ARM_SPI_Control (\ref ARM_SPI_CONTROL_SS)). The activation/deactivation of the line is completely hardware
694 dependent. Typically, the hardware will activate it before starting a transfer and deactivate it after a transfer completes.
695 Some hardware will leave it activated as long as the SPI stays master. Due to different hardware behavior, this mode is
696 typically not useful because certain devices require that the SS signal is strictly defined with regards to transfers.
698 \def ARM_SPI_SS_MASTER_HW_INPUT
699 This is normally used in a multi-master configuration, where a master does not drive the SS line when driving the bus but only
700 monitors it. When another master activates this line, the active master backs off. This is called \b mode \b fault. SS is
701 configured as input and the hardware only monitors it. When it is externally deactivated while being the master, it presents
702 a mode fault and the SPI switches to \b inactive mode.
704 \def ARM_SPI_SS_SLAVE_HW
705 Hardware monitors the SS line and accepts transfers only when SS line is activate. Transfers while SS is not active are
708 \def ARM_SPI_SS_SLAVE_SW
709 Used only when SS line is not used. For example, when a single master and slave are connected in a system, the SS line is not
710 needed (reduces the number of lines and pins used). Slave responses are controlled by software (by default, it is not
711 responding). Software enables/disables transfers by calling \ref ARM_SPI_Control (\ref ARM_SPI_CONTROL_SS, \ref ARM_SPI_SS_ACTIVE / \ref ARM_SPI_SS_INACTIVE).
717 \defgroup spi_misc_ctrls SPI Miscellaneous Controls
719 \brief Specifies additional miscellaneous controls.
722 \def ARM_SPI_SET_BUS_SPEED
724 \def ARM_SPI_GET_BUS_SPEED
726 \def ARM_SPI_SET_DEFAULT_TX_VALUE
728 \def ARM_SPI_CONTROL_SS
730 \def ARM_SPI_ABORT_TRANSFER
738 // end group SPI_control