nrfx 2.5
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
TWIS driver

Two Wire Interface Slave with EasyDMA (TWIS) peripheral driver. More...

Modules

 TWIS peripheral driver configuration
 

Data Structures

struct  nrfx_twis_t
 TWIS driver instance data structure. More...
 
struct  nrfx_twis_evt_t
 TWIS driver event structure. More...
 
struct  nrfx_twis_config_t
 Structure for TWIS configuration. More...
 

Macros

#define NRFX_TWIS_INSTANCE(id)
 Macro for creating a TWIS driver instance. More...
 
#define NRFX_TWIS_DEFAULT_CONFIG(_pin_scl, _pin_sda, _addr)
 TWIS driver default configuration. More...
 

Typedefs

typedef void(* nrfx_twis_event_handler_t) (nrfx_twis_evt_t const *p_event)
 TWI slave event callback function type. More...
 

Enumerations

enum  nrfx_twis_evt_type_t {
  NRFX_TWIS_EVT_READ_REQ,
  NRFX_TWIS_EVT_READ_DONE,
  NRFX_TWIS_EVT_READ_ERROR,
  NRFX_TWIS_EVT_WRITE_REQ,
  NRFX_TWIS_EVT_WRITE_DONE,
  NRFX_TWIS_EVT_WRITE_ERROR,
  NRFX_TWIS_EVT_GENERAL_ERROR
}
 Event callback function event definitions. More...
 
enum  nrfx_twis_error_t {
  NRFX_TWIS_ERROR_OVERFLOW = NRF_TWIS_ERROR_OVERFLOW,
  NRFX_TWIS_ERROR_DATA_NACK = NRF_TWIS_ERROR_DATA_NACK,
  NRFX_TWIS_ERROR_OVERREAD = NRF_TWIS_ERROR_OVERREAD,
  NRFX_TWIS_ERROR_UNEXPECTED_EVENT = 1 << 8
}
 Possible error sources. More...
 

Functions

nrfx_err_t nrfx_twis_init (nrfx_twis_t const *p_instance, nrfx_twis_config_t const *p_config, nrfx_twis_event_handler_t event_handler)
 Function for initializing the TWIS driver instance. More...
 
void nrfx_twis_uninit (nrfx_twis_t const *p_instance)
 Function for uninitializing the TWIS driver instance. More...
 
void nrfx_twis_enable (nrfx_twis_t const *p_instance)
 Function for enabling the TWIS instance. More...
 
void nrfx_twis_disable (nrfx_twis_t const *p_instance)
 Function for disabling the TWIS instance. More...
 
uint32_t nrfx_twis_error_get_and_clear (nrfx_twis_t const *p_instance)
 Function for getting and clearing the last error flags. More...
 
nrfx_err_t nrfx_twis_tx_prepare (nrfx_twis_t const *p_instance, void const *p_buf, size_t size)
 Function for preparing the data for sending. More...
 
NRFX_STATIC_INLINE size_t nrfx_twis_tx_amount (nrfx_twis_t const *p_instance)
 Function for getting the number of transmitted bytes. More...
 
nrfx_err_t nrfx_twis_rx_prepare (nrfx_twis_t const *p_instance, void *p_buf, size_t size)
 Function for preparing the data for receiving. More...
 
NRFX_STATIC_INLINE size_t nrfx_twis_rx_amount (nrfx_twis_t const *p_instance)
 Function for getting the number of received bytes. More...
 
bool nrfx_twis_is_busy (nrfx_twis_t const *p_instance)
 Function for checking if the driver is busy right now. More...
 
bool nrfx_twis_is_waiting_tx_buff (nrfx_twis_t const *p_instance)
 Function for checking if the driver is waiting for a TX buffer. More...
 
bool nrfx_twis_is_waiting_rx_buff (nrfx_twis_t const *p_instance)
 Function for checking if the driver is waiting for an RX buffer. More...
 
bool nrfx_twis_is_pending_tx (nrfx_twis_t const *p_instance)
 Function for checking if the driver is sending data. More...
 
bool nrfx_twis_is_pending_rx (nrfx_twis_t const *p_instance)
 Function for checking if the driver is receiving data. More...
 

Detailed Description

Two Wire Interface Slave with EasyDMA (TWIS) peripheral driver.

Macro Definition Documentation

◆ NRFX_TWIS_DEFAULT_CONFIG

#define NRFX_TWIS_DEFAULT_CONFIG (   _pin_scl,
  _pin_sda,
  _addr 
)
Value:
{ \
.addr = { _addr, 0x00 }, \
.scl = _pin_scl, \
.sda = _pin_sda, \
.scl_pull = NRF_GPIO_PIN_NOPULL, \
.sda_pull = NRF_GPIO_PIN_NOPULL, \
.interrupt_priority = NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY \
}
Pin pull-up resistor disabled.
Definition: nrf_gpio.h:66
#define NRFX_TWIS_DEFAULT_CONFIG_IRQ_PRIORITY
Interrupt priority.
Definition: nrfx_twis_dox_config.h:65

TWIS driver default configuration.

This configuration sets up TWIS with the following options:

  • second slave address disabled
  • SCL pull-up disabled
  • SDA pull-up disabled
Parameters
[in]_pin_sclSCL pin.
[in]_pin_sdaSDA pin.
[in]_addrSlave address on TWI bus.

◆ NRFX_TWIS_INSTANCE

#define NRFX_TWIS_INSTANCE (   id)
Value:
{ \
.p_reg = NRFX_CONCAT_2(NRF_TWIS, id), \
.drv_inst_idx = NRFX_CONCAT_3(NRFX_TWIS, id, _INST_IDX), \
}
#define NRFX_CONCAT_2(p1, p2)
Macro for concatenating two tokens in macro expansion.
Definition: nrfx_common.h:67
#define NRFX_CONCAT_3(p1, p2, p3)
Macro for concatenating three tokens in macro expansion.
Definition: nrfx_common.h:88

Macro for creating a TWIS driver instance.

Typedef Documentation

◆ nrfx_twis_event_handler_t

typedef void(* nrfx_twis_event_handler_t) (nrfx_twis_evt_t const *p_event)

TWI slave event callback function type.

Parameters
[in]p_eventEvent information structure.

Enumeration Type Documentation

◆ nrfx_twis_error_t

Possible error sources.

This is flag enum - values from this enum can be connected using logical or operator.

Note
You can use directly nrf_twis_error_t. Error type enum is redefined here because of possible future extension (eg. supporting timeouts and synchronous mode).
Enumerator
NRFX_TWIS_ERROR_OVERFLOW 

RX buffer overflow detected, and prevented.

NRFX_TWIS_ERROR_DATA_NACK 

NACK sent after receiving a data byte.

NRFX_TWIS_ERROR_OVERREAD 

TX buffer over-read detected, and prevented.

NRFX_TWIS_ERROR_UNEXPECTED_EVENT 

Unexpected event detected by state machine.

◆ nrfx_twis_evt_type_t

Event callback function event definitions.

Enumerator
NRFX_TWIS_EVT_READ_REQ 

Read request detected.

If there is no buffer prepared, buf_req flag in the even will be set. Call then nrfx_twis_tx_prepare to give parameters for buffer.

NRFX_TWIS_EVT_READ_DONE 

Read request finished - free any data.

NRFX_TWIS_EVT_READ_ERROR 

Read request finished with error.

NRFX_TWIS_EVT_WRITE_REQ 

Write request detected.

If there is no buffer prepared, buf_req flag in the even will be set. Call then nrfx_twis_rx_prepare to give parameters for buffer.

NRFX_TWIS_EVT_WRITE_DONE 

Write request finished - process data.

NRFX_TWIS_EVT_WRITE_ERROR 

Write request finished with error.

NRFX_TWIS_EVT_GENERAL_ERROR 

Error that happens not inside WRITE or READ transaction.

Function Documentation

◆ nrfx_twis_disable()

void nrfx_twis_disable ( nrfx_twis_t const *  p_instance)

Function for disabling the TWIS instance.

This function disables the TWIS instance, which gives possibility to turn off the TWIS while holding configuration done by nrfx_twis_init.

Parameters
p_instancePointer to the driver instance structure.

◆ nrfx_twis_enable()

void nrfx_twis_enable ( nrfx_twis_t const *  p_instance)

Function for enabling the TWIS instance.

This function enables the TWIS instance. Function defined if there is need for dynamically enabling and disabling the peripheral. Use nrfx_twis_enable and nrfx_twis_disable functions. They do not change any configuration registers.

Parameters
p_instancePointer to the driver instance structure.

◆ nrfx_twis_error_get_and_clear()

uint32_t nrfx_twis_error_get_and_clear ( nrfx_twis_t const *  p_instance)

Function for getting and clearing the last error flags.

This function gets the information about errors. This is also the only possibility to exit from the error substate of the internal state machine.

Attention
This function clears error state and flags.
Parameters
[in]p_instancePointer to the driver instance structure.
Returns
Error flags defined in nrfx_twis_error_t.

◆ nrfx_twis_init()

nrfx_err_t nrfx_twis_init ( nrfx_twis_t const *  p_instance,
nrfx_twis_config_t const *  p_config,
nrfx_twis_event_handler_t  event_handler 
)

Function for initializing the TWIS driver instance.

Function initializes and enables the TWIS driver.

Attention
After driver initialization enable it with nrfx_twis_enable.
Parameters
[in]p_instancePointer to the driver instance structure.
Attention
p_instance has to be global object. It will be used by interrupts so make it sure that object is not destroyed when function is leaving.
Parameters
[in]p_configPointer to the structure with the initial configuration.
[in]event_handlerEvent handler provided by the user.
Return values
NRFX_SUCCESSInitialization is successful.
NRFX_ERROR_INVALID_STATEThe driver is already initialized.
NRFX_ERROR_BUSYSome other peripheral with the same instance ID is already in use. This is possible only if NRFX_PRS_ENABLED is set to a value other than zero.

◆ nrfx_twis_is_busy()

bool nrfx_twis_is_busy ( nrfx_twis_t const *  p_instance)

Function for checking if the driver is busy right now.

This function tests the actual driver substate. If the driver is in any other state than IDLE or ERROR, this function returns true.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueThe driver is in state other than ERROR or IDLE.
falseThere is no transmission pending.

◆ nrfx_twis_is_pending_rx()

bool nrfx_twis_is_pending_rx ( nrfx_twis_t const *  p_instance)

Function for checking if the driver is receiving data.

If this function returns true, there is an ongoing input transmission.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueThere is an ongoing input transmission.
falseThe driver is in other state.

◆ nrfx_twis_is_pending_tx()

bool nrfx_twis_is_pending_tx ( nrfx_twis_t const *  p_instance)

Function for checking if the driver is sending data.

If this function returns true, there is an ongoing output transmission.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueThere is an ongoing output transmission.
falseThe driver is in other state.

◆ nrfx_twis_is_waiting_rx_buff()

bool nrfx_twis_is_waiting_rx_buff ( nrfx_twis_t const *  p_instance)

Function for checking if the driver is waiting for an RX buffer.

If this function returns true, the driver is stalled expecting of the nrfx_twis_rx_prepare function call.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueThe driver is waiting for nrfx_twis_rx_prepare.
falseThe driver is not in the state where it is waiting for preparing an RX buffer.

◆ nrfx_twis_is_waiting_tx_buff()

bool nrfx_twis_is_waiting_tx_buff ( nrfx_twis_t const *  p_instance)

Function for checking if the driver is waiting for a TX buffer.

If this function returns true, the driver is stalled expecting of the nrfx_twis_tx_prepare function call.

Parameters
[in]p_instancePointer to the driver instance structure.
Return values
trueThe driver is waiting for nrfx_twis_tx_prepare.
falseThe driver is not in the state where it is waiting for preparing a TX buffer.

◆ nrfx_twis_rx_amount()

NRFX_STATIC_INLINE size_t nrfx_twis_rx_amount ( nrfx_twis_t const *  p_instance)

Function for getting the number of received bytes.

This function returns number of bytes received. It can be called after NRFX_TWIS_EVT_WRITE_DONE or NRFX_TWIS_EVT_WRITE_ERROR events.

Parameters
[in]p_instancePointer to the driver instance structure.
Returns
Number of bytes received.

◆ nrfx_twis_rx_prepare()

nrfx_err_t nrfx_twis_rx_prepare ( nrfx_twis_t const *  p_instance,
void *  p_buf,
size_t  size 
)

Function for preparing the data for receiving.

This function must be used in response to the NRFX_TWIS_EVT_WRITE_REQ event.

Note
Peripherals using EasyDMA (including TWIS) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function fails with the error code NRFX_ERROR_INVALID_ADDR.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_bufBuffer that is to be filled with received data.
[in]sizeSize of the buffer (maximum amount of data to receive).
Return values
NRFX_SUCCESSThe preparation finished properly.
NRFX_ERROR_INVALID_ADDRThe given p_buf is not placed inside the RAM.
NRFX_ERROR_INVALID_LENGTHThere is a wrong value in the size parameter.
NRFX_ERROR_INVALID_STATEThe module is not initialized or not enabled.

◆ nrfx_twis_tx_amount()

NRFX_STATIC_INLINE size_t nrfx_twis_tx_amount ( nrfx_twis_t const *  p_instance)

Function for getting the number of transmitted bytes.

This function returns the number of bytes sent. This function can be called after NRFX_TWIS_EVT_READ_DONE or NRFX_TWIS_EVT_READ_ERROR events.

Parameters
[in]p_instancePointer to the driver instance structure.
Returns
Number of bytes sent.

◆ nrfx_twis_tx_prepare()

nrfx_err_t nrfx_twis_tx_prepare ( nrfx_twis_t const *  p_instance,
void const *  p_buf,
size_t  size 
)

Function for preparing the data for sending.

This function is to be used in response to the NRFX_TWIS_EVT_READ_REQ event.

Note
Peripherals using EasyDMA (including TWIS) 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.
Attention
Transmission buffer must be placed in RAM.
Parameters
[in]p_instancePointer to the driver instance structure.
[in]p_bufTransmission buffer.
[in]sizeMaximum number of bytes that master may read from buffer given.
Return values
NRFX_SUCCESSThe preparation finished properly.
NRFX_ERROR_INVALID_ADDRThe given p_buf is not placed inside the RAM.
NRFX_ERROR_INVALID_LENGTHThere is a wrong value in the size parameter.
NRFX_ERROR_INVALID_STATEThe module is not initialized or not enabled.

◆ nrfx_twis_uninit()

void nrfx_twis_uninit ( nrfx_twis_t const *  p_instance)

Function for uninitializing the TWIS driver instance.

Function uninitializes the peripheral and resets all registers to default values.

Note
It is safe to call nrfx_twis_uninit even before initialization. Actually, nrfx_twis_init function calls this function to make sure that TWIS state is known.
If TWIS driver was in uninitialized state before calling this function, the selected pins would not be reset to default configuration.
Parameters
[in]p_instancePointer to the driver instance structure.

Documentation feedback | Developer Zone | Subscribe | Updated