SPIM peripheral driver.
More...
|
#define | NRFX_SPIM_INSTANCE(id) |
| Macro for creating an SPIM master driver instance. More...
|
|
#define | NRFX_SPIM_PIN_NOT_USED 0xFF |
| This value can be provided instead of a pin number for signals MOSI, MISO, and Slave Select to specify that the given signal is not used and therefore does not need to be connected to a pin.
|
|
#define | NRFX_SPIM_DEFAULT_EXTENDED_CONFIG |
| SPIM master instance extended default configuration. More...
|
|
#define | NRFX_SPIM_DEFAULT_CONFIG |
| SPIM master instance default configuration. More...
|
|
#define | NRFX_SPIM_FLAG_TX_POSTINC (1UL << 0) |
|
#define | NRFX_SPIM_FLAG_RX_POSTINC (1UL << 1) |
|
#define | NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) |
|
#define | NRFX_SPIM_FLAG_HOLD_XFER (1UL << 3) |
|
#define | NRFX_SPIM_FLAG_REPEATED_XFER (1UL << 4) |
|
#define | NRFX_SPIM_SINGLE_XFER(p_tx, tx_len, p_rx, rx_len) |
| Macro for setting up single transfer descriptor. More...
|
|
#define | NRFX_SPIM_XFER_TRX(p_tx_buf, tx_length, p_rx_buf, rx_length) NRFX_SPIM_SINGLE_XFER(p_tx_buf, tx_length, p_rx_buf, rx_length) |
| Macro for setting duplex TX RX transfer.
|
|
#define | NRFX_SPIM_XFER_TX(p_buf, length) NRFX_SPIM_SINGLE_XFER(p_buf, length, NULL, 0) |
| Macro for setting TX transfer.
|
|
#define | NRFX_SPIM_XFER_RX(p_buf, length) NRFX_SPIM_SINGLE_XFER(NULL, 0, p_buf, length) |
| Macro for setting RX transfer.
|
|
SPIM peripheral driver.
#define NRFX_SPIM_DEFAULT_CONFIG |
Value:{ \
.ss_active_high = false, \
.orc = 0xFF, \
NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
}
SPIM master instance default configuration.
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG |
Value:
.rx_delay = 0x02, \
.ss_duration = 0x02, \
.use_hw_ss = false,
SPIM master instance extended default configuration.
#define NRFX_SPIM_FLAG_HOLD_XFER (1UL << 3) |
Set up the transfer but do not start it.
#define NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) |
Interrupt after each transfer is suppressed, and the event handler is not called.
#define NRFX_SPIM_FLAG_REPEATED_XFER (1UL << 4) |
Flag indicating that the transfer will be executed multiple times.
#define NRFX_SPIM_FLAG_RX_POSTINC (1UL << 1) |
RX buffer address incremented after transfer.
#define NRFX_SPIM_FLAG_TX_POSTINC (1UL << 0) |
TX buffer address incremented after transfer.
#define NRFX_SPIM_INSTANCE |
( |
|
id | ) |
|
Value:
Macro for creating an SPIM master driver instance.
#define NRFX_SPIM_SINGLE_XFER |
( |
|
p_tx, |
|
|
|
tx_len, |
|
|
|
p_rx, |
|
|
|
rx_len |
|
) |
| |
Value:{ \
.p_tx_buffer = (uint8_t const *)(p_tx), \
.tx_length = (tx_len), \
.p_rx_buffer = (p_rx), \
.rx_length = (rx_len), \
}
Macro for setting up single transfer descriptor.
This macro is for internal use only.
SPIM master driver event types, passed to the handler routine provided during initialization.
Enumerator |
---|
NRFX_SPIM_EVENT_DONE |
Transfer done.
|
Function for aborting ongoing transfer.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
uint32_t nrfx_spim_end_event_get |
( |
nrfx_spim_t const * |
p_instance | ) |
|
Function for returning the address of a END SPIM event.
The END event can be used to detect the end of a transfer if the NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER option is used.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
- Returns
- END event address.
Function for initializing the SPI master driver instance.
This function configures and enables the specified peripheral.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
[in] | p_config | Pointer to the structure with initial configuration. |
| handler | Event handler provided by the user. If NULL, transfers will be performed in blocking mode. |
| p_context | Context passed to event handler. |
- Return values
-
NRFX_SUCCESS | If initialization was successful. |
NRFX_ERROR_INVALID_STATE | If the driver was already initialized. |
NRFX_ERROR_BUSY | If some other peripheral with the same instance ID is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled. |
NRFX_ERROR_NOT_SUPPORTED | If requested configuration is not supported by the SPIM instance. |
uint32_t nrfx_spim_start_task_get |
( |
nrfx_spim_t const * |
p_instance | ) |
|
Function for returning the address of a SPIM start task.
This function should be used if nrfx_spim_xfer was called with the flag NRFX_SPIM_FLAG_HOLD_XFER. In that case, the transfer is not started by the driver, but it must be started externally by PPI.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
- Returns
- Start task address.
void nrfx_spim_uninit |
( |
nrfx_spim_t const *const |
p_instance | ) |
|
Function for uninitializing the SPI master driver instance.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
Function for starting the SPI data transfer.
Additional options are provided using the flags
parameter:
- NRFX_SPIM_FLAG_TX_POSTINC and NRFX_SPIM_FLAG_RX_POSTINC: Post-incrementation of buffer addresses. Supported only by SPIM.
- NRFX_SPIM_FLAG_HOLD_XFER: Driver is not starting the transfer. Use this flag if the transfer is triggered externally by PPI. Supported only by SPIM. Use nrfx_spim_start_task_get to get the address of the start task.
- NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER: No user event handler after transfer completion. This also means no interrupt at the end of the transfer. Supported only by SPIM. If NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER is used, the driver does not set the instance into busy state, so you must ensure that the next transfers are set up when SPIM is not active. nrfx_spim_end_event_get function can be used to detect end of transfer. Option can be used together with NRFX_SPIM_FLAG_REPEATED_XFER to prepare a sequence of SPI transfers without interruptions.
- NRFX_SPIM_FLAG_REPEATED_XFER: Prepare for repeated transfers. You can set up a number of transfers that will be triggered externally (for example by PPI). An example is a TXRX transfer with the options NRFX_SPIM_FLAG_RX_POSTINC, NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER, and NRFX_SPIM_FLAG_REPEATED_XFER. After the transfer is set up, a set of transfers can be triggered by PPI that will read, for example, the same register of an external component and put it into a RAM buffer without any interrupts. nrfx_spim_end_event_get can be used to get the address of the END event, which can be used to count the number of transfers. If NRFX_SPIM_FLAG_REPEATED_XFER is used, the driver does not set the instance into busy state, so you must ensure that the next transfers are set up when SPIM is not active. Supported only by SPIM.
- Note
- Peripherals using EasyDMA (including SPIM) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will fail with the error code NRFX_ERROR_INVALID_ADDR.
- Parameters
-
p_instance | Pointer to the driver instance structure. |
p_xfer_desc | Pointer to the transfer descriptor. |
flags | Transfer options (0 for default settings). |
- Return values
-
NRFX_SUCCESS | If the procedure was successful. |
NRFX_ERROR_BUSY | If the driver is not ready for a new transfer. |
NRFX_ERROR_NOT_SUPPORTED | If the provided parameters are not supported. |
NRFX_ERROR_INVALID_ADDR | If the provided buffers are not placed in the Data RAM region. |
Function for starting the SPI data transfer with DCX control.
See nrfx_spim_xfer for description of additional options of transfer provided by the flags
parameter.
- Note
- Peripherals that use EasyDMA (including SPIM) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will fail with the error code NRFX_ERROR_INVALID_ADDR.
- Parameters
-
p_instance | Pointer to the driver instance structure. |
p_xfer_desc | Pointer to the transfer descriptor. |
flags | Transfer options (0 for default settings). |
cmd_length | Length of the command bytes preceding the data bytes. The DCX line will be low during transmission of command bytes and high during transmission of data bytes. Maximum value available for dividing the transmitted bytes into command bytes and data bytes is NRF_SPIM_DCX_CNT_ALL_CMD - 1. The NRF_SPIM_DCX_CNT_ALL_CMD value passed as the cmd_length parameter causes all transmitted bytes to be marked as command bytes. |
- Return values
-
NRFX_SUCCESS | If the procedure was successful. |
NRFX_ERROR_BUSY | If the driver is not ready for a new transfer. |
NRFX_ERROR_NOT_SUPPORTED | If the provided parameters are not supported. |
NRFX_ERROR_INVALID_ADDR | If the provided buffers are not placed in the Data RAM region. |