Two Wire Interface Master with EasyDMA (TWIM) peripheral driver. More...
Modules | |
TWIM peripheral driver configuration | |
Data Structures | |
struct | nrfx_twim_t |
Structure for the TWI master driver instance. More... | |
struct | nrfx_twim_config_t |
Structure for the TWI master driver instance configuration. More... | |
struct | nrfx_twim_xfer_desc_t |
Structure for a TWI transfer descriptor. More... | |
struct | nrfx_twim_evt_t |
Structure for a TWI event. More... | |
Macros | |
#define | NRFX_TWIM_INSTANCE(id) |
Macro for creating a TWI master driver instance. More... | |
#define | NRFX_TWIM_DEFAULT_CONFIG(_pin_scl, _pin_sda) |
TWIM driver default configuration. More... | |
#define | NRFX_TWIM_FLAG_TX_POSTINC (1UL << 0) |
Flag indicating that TX buffer address will be incremented after the transfer. | |
#define | NRFX_TWIM_FLAG_RX_POSTINC (1UL << 1) |
Flag indicating that RX buffer address will be incremented after the transfer. | |
#define | NRFX_TWIM_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) |
Flag indicating that the interrupt after each transfer will be suppressed, and the event handler will not be called. | |
#define | NRFX_TWIM_FLAG_HOLD_XFER (1UL << 3) |
Flag indicating that the transfer will be set up, but not started. | |
#define | NRFX_TWIM_FLAG_REPEATED_XFER (1UL << 4) |
Flag indicating that the transfer will be executed multiple times. | |
#define | NRFX_TWIM_FLAG_TX_NO_STOP (1UL << 5) |
Flag indicating that the TX transfer will not end with a stop condition. | |
#define | NRFX_TWIM_FLAG_NO_SPURIOUS_STOP_CHECK (1UL << 6) |
Flag indicating that checks for spurious STOP condition will not be performed. | |
#define | NRFX_TWIM_XFER_DESC_TX(addr, p_data, length) |
Macro for setting the TX transfer descriptor. More... | |
#define | NRFX_TWIM_XFER_DESC_RX(addr, p_data, length) |
Macro for setting the RX transfer descriptor. More... | |
#define | NRFX_TWIM_XFER_DESC_TXRX(addr, p_tx, tx_len, p_rx, rx_len) |
Macro for setting the TX-RX transfer descriptor. More... | |
#define | NRFX_TWIM_XFER_DESC_TXTX(addr, p_tx, tx_len, p_tx2, tx_len2) |
Macro for setting the TX-TX transfer descriptor. More... | |
Typedefs | |
typedef void(* | nrfx_twim_evt_handler_t) (nrfx_twim_evt_t const *p_event, void *p_context) |
TWI event handler prototype. | |
Enumerations | |
enum | nrfx_twim_evt_type_t { NRFX_TWIM_EVT_DONE, NRFX_TWIM_EVT_ADDRESS_NACK, NRFX_TWIM_EVT_DATA_NACK, NRFX_TWIM_EVT_OVERRUN, NRFX_TWIM_EVT_BUS_ERROR } |
TWI master driver event types. More... | |
enum | nrfx_twim_xfer_type_t { NRFX_TWIM_XFER_TX, NRFX_TWIM_XFER_RX, NRFX_TWIM_XFER_TXRX, NRFX_TWIM_XFER_TXTX } |
TWI master driver transfer types. More... | |
Functions | |
nrfx_err_t | nrfx_twim_init (nrfx_twim_t const *p_instance, nrfx_twim_config_t const *p_config, nrfx_twim_evt_handler_t event_handler, void *p_context) |
Function for initializing the TWI driver instance. More... | |
void | nrfx_twim_uninit (nrfx_twim_t const *p_instance) |
Function for uninitializing the TWI instance. More... | |
void | nrfx_twim_enable (nrfx_twim_t const *p_instance) |
Function for enabling the TWI instance. More... | |
void | nrfx_twim_disable (nrfx_twim_t const *p_instance) |
Function for disabling the TWI instance. More... | |
nrfx_err_t | nrfx_twim_xfer (nrfx_twim_t const *p_instance, nrfx_twim_xfer_desc_t const *p_xfer_desc, uint32_t flags) |
Function for performing a TWI transfer. More... | |
bool | nrfx_twim_is_busy (nrfx_twim_t const *p_instance) |
Function for checking the TWI driver state. More... | |
uint32_t | nrfx_twim_start_task_get (nrfx_twim_t const *p_instance, nrfx_twim_xfer_type_t xfer_type) |
Function for returning the address of a TWIM start task. More... | |
uint32_t | nrfx_twim_stopped_event_get (nrfx_twim_t const *p_instance) |
Function for returning the address of a STOPPED TWIM event. More... | |
NRFX_STATIC_INLINE nrfx_err_t | nrfx_twim_bus_recover (uint32_t scl_pin, uint32_t sda_pin) |
Function for recovering the bus. More... | |
Two Wire Interface Master with EasyDMA (TWIM) peripheral driver.
#define NRFX_TWIM_DEFAULT_CONFIG | ( | _pin_scl, | |
_pin_sda | |||
) |
TWIM driver default configuration.
This configuration sets up TWIM with the following options:
[in] | _pin_scl | SCL pin. |
[in] | _pin_sda | SDA pin. |
#define NRFX_TWIM_INSTANCE | ( | id | ) |
Macro for creating a TWI master driver instance.
#define NRFX_TWIM_XFER_DESC_RX | ( | addr, | |
p_data, | |||
length | |||
) |
Macro for setting the RX transfer descriptor.
#define NRFX_TWIM_XFER_DESC_TX | ( | addr, | |
p_data, | |||
length | |||
) |
Macro for setting the TX transfer descriptor.
#define NRFX_TWIM_XFER_DESC_TXRX | ( | addr, | |
p_tx, | |||
tx_len, | |||
p_rx, | |||
rx_len | |||
) |
Macro for setting the TX-RX transfer descriptor.
#define NRFX_TWIM_XFER_DESC_TXTX | ( | addr, | |
p_tx, | |||
tx_len, | |||
p_tx2, | |||
tx_len2 | |||
) |
Macro for setting the TX-TX transfer descriptor.
enum nrfx_twim_evt_type_t |
TWI master driver event types.
NRFX_STATIC_INLINE nrfx_err_t nrfx_twim_bus_recover | ( | uint32_t | scl_pin, |
uint32_t | sda_pin | ||
) |
Function for recovering the bus.
This function checks if the bus is not stuck because of a slave holding the SDA line in the low state, and if needed it performs required number of pulses on the SCL line to make the slave release the SDA line. Finally, the function generates a STOP condition on the bus to put it into a known state.
[in] | scl_pin | SCL pin number. |
[in] | sda_pin | SDA pin number. |
NRFX_SUCCESS | Bus recovery was successful. |
NRFX_ERROR_INTERNAL | Bus recovery failed. |
void nrfx_twim_disable | ( | nrfx_twim_t const * | p_instance | ) |
Function for disabling the TWI instance.
[in] | p_instance | Pointer to the driver instance structure. |
void nrfx_twim_enable | ( | nrfx_twim_t const * | p_instance | ) |
Function for enabling the TWI instance.
[in] | p_instance | Pointer to the driver instance structure. |
nrfx_err_t nrfx_twim_init | ( | nrfx_twim_t const * | p_instance, |
nrfx_twim_config_t const * | p_config, | ||
nrfx_twim_evt_handler_t | event_handler, | ||
void * | p_context | ||
) |
Function for initializing the TWI driver instance.
[in] | p_instance | Pointer to the driver instance structure. |
[in] | p_config | Pointer to the structure with the initial configuration. |
[in] | event_handler | Event handler provided by the user. If NULL, blocking mode is enabled. |
[in] | p_context | Context passed to event handler. |
NRFX_SUCCESS | Initialization was successful. |
NRFX_ERROR_INVALID_STATE | The driver is in invalid state. |
NRFX_ERROR_INVALID_PARAM | Requested frequency is not available on the specified pins. |
NRFX_ERROR_BUSY | Some other peripheral with the same instance ID is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled. |
bool nrfx_twim_is_busy | ( | nrfx_twim_t const * | p_instance | ) |
Function for checking the TWI driver state.
[in] | p_instance | TWI instance. |
true | The TWI driver is currently busy performing a transfer. |
false | The TWI driver is ready for a new transfer. |
uint32_t nrfx_twim_start_task_get | ( | nrfx_twim_t const * | p_instance, |
nrfx_twim_xfer_type_t | xfer_type | ||
) |
Function for returning the address of a TWIM start task.
This function is to be used if nrfx_twim_xfer was called with the flag NRFX_TWIM_FLAG_HOLD_XFER. In that case, the transfer is not started by the driver, but it must be started externally by PPI.
[in] | p_instance | Pointer to the driver instance structure. |
[in] | xfer_type | Transfer type used in the last call of the nrfx_twim_xfer function. |
uint32_t nrfx_twim_stopped_event_get | ( | nrfx_twim_t const * | p_instance | ) |
Function for returning the address of a STOPPED TWIM event.
A STOPPED event can be used to detect the end of a transfer if the NRFX_TWIM_FLAG_NO_XFER_EVT_HANDLER option is used.
[in] | p_instance | Pointer to the driver instance structure. |
void nrfx_twim_uninit | ( | nrfx_twim_t const * | p_instance | ) |
Function for uninitializing the TWI instance.
[in] | p_instance | Pointer to the driver instance structure. |
nrfx_err_t nrfx_twim_xfer | ( | nrfx_twim_t const * | p_instance, |
nrfx_twim_xfer_desc_t const * | p_xfer_desc, | ||
uint32_t | flags | ||
) |
Function for performing a TWI transfer.
The following transfer types can be configured (nrfx_twim_xfer_desc_t::type):
Additional options are provided using the flags parameter:
If nrfx_twim_xfer_desc_t::type is set to NRFX_TWIM_XFER_TX and the NRFX_TWIM_FLAG_TX_NO_STOP and NRFX_TWIM_FLAG_REPEATED_XFER flags are set, two tasks must be used to trigger a transfer: TASKS_RESUME followed by TASKS_STARTTX. If no stop condition is generated, TWIM is in SUSPENDED state. Therefore, it must be resumed before the transfer can be started.
[in] | p_instance | Pointer to the driver instance structure. |
[in] | p_xfer_desc | Pointer to the transfer descriptor. |
[in] | flags | Transfer options (0 for default settings). |
NRFX_SUCCESS | The procedure is successful. |
NRFX_ERROR_BUSY | The driver is not ready for a new transfer. |
NRFX_ERROR_NOT_SUPPORTED | The provided parameters are not supported. |
NRFX_ERROR_INTERNAL | An unexpected transition occurred on the bus. |
NRFX_ERROR_INVALID_ADDR | The provided buffers are not placed in the Data RAM region. |
NRFX_ERROR_DRV_TWI_ERR_OVERRUN | The unread data is replaced by new data. |
NRFX_ERROR_DRV_TWI_ERR_ANACK | NACK is received after sending the address. |
NRFX_ERROR_DRV_TWI_ERR_DNACK | NACK is received after sending a data byte. |