nRF51 SDK - S110 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Driver for managing the TWI. More...

Data Structures

struct  nrf_drv_twi_evt_t
 Structure for a TWI event. More...
 
struct  nrf_drv_twi_t
 TWI driver instance structure. More...
 
struct  nrf_drv_twi_config_t
 Structure for TWI instance configuration. More...
 

Macros

#define NRF_DRV_TWI_INSTANCE(id)
 Macro for creating a TWI driver instance. More...
 
#define TWI_CONFIG_FREQUENCY(id)   TWI##id##_CONFIG_FREQUENCY
 
#define TWI_CONFIG_SCL(id)   TWI##id##_CONFIG_SCL
 
#define TWI_CONFIG_SDA(id)   TWI##id##_CONFIG_SDA
 
#define TWI_CONFIG_IRQ_PRIORITY(id)   TWI##id##_CONFIG_IRQ_PRIORITY
 
#define NRF_DRV_TWI_DEFAULT_CONFIG(id)
 TWI instance default configuration. More...
 

Typedefs

typedef void(* nrf_drv_twi_evt_handler_t )(nrf_drv_twi_evt_t *p_event)
 TWI event handler prototype.
 

Enumerations

enum  nrf_drv_twi_evt_type_t {
  NRF_DRV_TWI_RX_DONE,
  NRF_DRV_TWI_TX_DONE,
  NRF_DRV_TWI_ERROR
}
 TWI events.
 

Functions

ret_code_t nrf_drv_twi_init (nrf_drv_twi_t const *const p_instance, nrf_drv_twi_config_t const *p_config, nrf_drv_twi_evt_handler_t event_handler)
 Function for initializing the TWI instance. More...
 
void nrf_drv_twi_uninit (nrf_drv_twi_t const *const p_instance)
 Function for uninitializing the TWI. More...
 
void nrf_drv_twi_enable (nrf_drv_twi_t const *const p_instance)
 Function for enabling the TWI instance. More...
 
void nrf_drv_twi_disable (nrf_drv_twi_t const *const p_instance)
 Function for disabling the TWI instance. More...
 
ret_code_t nrf_drv_twi_tx (nrf_drv_twi_t const *const p_instance, uint8_t address, uint8_t const *p_data, uint32_t length, bool xfer_pending)
 Function for sending data to a TWI slave. More...
 
ret_code_t nrf_drv_twi_rx (nrf_drv_twi_t const *const p_instance, uint8_t address, uint8_t *p_data, uint32_t length, bool xfer_pending)
 Function for reading data from a TWI slave. More...
 
uint32_t nrf_data_count_get (nrf_drv_twi_t const *const p_instance)
 Function for getting transferred data count. More...
 
__STATIC_INLINE uint32_t nrf_drv_twi_task_address_get (nrf_drv_twi_t const *const p_instance, nrf_twi_tasks_t task)
 Function for returning the address of a specific TWI task. More...
 
__STATIC_INLINE uint32_t nrf_drv_twi_event_address_get (nrf_drv_twi_t const *const p_instance, nrf_twi_events_t event)
 Function for returning the address of a specific TWI event. More...
 

Detailed Description

Driver for managing the TWI.

Macro Definition Documentation

#define NRF_DRV_TWI_DEFAULT_CONFIG (   id)
Value:
{ \
.frequency = TWI_CONFIG_FREQUENCY(id), \
.scl = TWI_CONFIG_SCL(id), \
.sda = TWI_CONFIG_SDA(id), \
.interrupt_priority = TWI_CONFIG_IRQ_PRIORITY(id), \
}

TWI instance default configuration.

#define NRF_DRV_TWI_INSTANCE (   id)
Value:
{ \
.p_reg = NRF_TWI##id, \
.irq = SPI##id##_TWI##id##_IRQn, \
.instance_id = TWI##id##_INSTANCE_INDEX \
}

Macro for creating a TWI driver instance.

Function Documentation

uint32_t nrf_data_count_get ( nrf_drv_twi_t const *const  p_instance)

Function for getting transferred data count.

Parameters
[in]p_instanceTWI instance.
Returns
Data count.
void nrf_drv_twi_disable ( nrf_drv_twi_t const *const  p_instance)

Function for disabling the TWI instance.

Parameters
[in]p_instanceTWI instance.
void nrf_drv_twi_enable ( nrf_drv_twi_t const *const  p_instance)

Function for enabling the TWI instance.

Parameters
[in]p_instanceTWI instance.
__STATIC_INLINE uint32_t nrf_drv_twi_event_address_get ( nrf_drv_twi_t const *const  p_instance,
nrf_twi_events_t  event 
)

Function for returning the address of a specific TWI event.

Parameters
[in]p_instanceTWI instance.
[in]eventEvent.
Returns
Event address.
ret_code_t nrf_drv_twi_init ( nrf_drv_twi_t const *const  p_instance,
nrf_drv_twi_config_t const *  p_config,
nrf_drv_twi_evt_handler_t  event_handler 
)

Function for initializing the TWI instance.

Parameters
[in]p_instanceTWI instance.
[in]p_configInitial configuration. If NULL, the default configuration is used.
[in]event_handlerEvent handler provided by the user. If NULL, blocking mode is enabled.
Return values
NRF_SUCCESSIf initialization was successful.
NRF_ERROR_INVALID_STATEIf the driver is in invalid state.
ret_code_t nrf_drv_twi_rx ( nrf_drv_twi_t const *const  p_instance,
uint8_t  address,
uint8_t *  p_data,
uint32_t  length,
bool  xfer_pending 
)

Function for reading data from a TWI slave.

Transmission will be stopped when error or time-out occurs.

Parameters
[in]p_instanceTWI instance.
[in]addressAddress of a specific slave device (only 7 LSB).
[in]p_dataPointer to a receive buffer.
[in]lengthNumber of bytes to be received.
[in]xfer_pendingAfter a specified number of bytes, transmission will be suspended (if xfer_pending is set) or stopped (if not).
Return values
NRF_SUCCESSIf the procedure was successful.
NRF_ERROR_BUSYIf the driver is not ready for a new transfer.
NRF_ERROR_INTERNALIf an NRF_TWI_EVENTS_ERROR or a time-out has occured (only in blocking mode).
__STATIC_INLINE uint32_t nrf_drv_twi_task_address_get ( nrf_drv_twi_t const *const  p_instance,
nrf_twi_tasks_t  task 
)

Function for returning the address of a specific TWI task.

Parameters
[in]p_instanceTWI instance.
[in]taskTask.
Returns
Task address.
ret_code_t nrf_drv_twi_tx ( nrf_drv_twi_t const *const  p_instance,
uint8_t  address,
uint8_t const *  p_data,
uint32_t  length,
bool  xfer_pending 
)

Function for sending data to a TWI slave.

The transmission will be stopped when an error or time-out occurs.

Parameters
[in]p_instanceTWI instance.
[in]addressAddress of a specific slave device (only 7 LSB).
[in]p_dataPointer to a transmit buffer.
[in]lengthNumber of bytes to send.
[in]xfer_pendingAfter a specified number of bytes, transmission will be suspended (if xfer_pending is set) or stopped (if not).
Return values
NRF_SUCCESSIf the procedure was successful.
NRF_ERROR_BUSYIf the driver is not ready for a new transfer.
NRF_ERROR_INTERNALIf an NRF_TWI_EVENTS_ERROR or a time-out has occurred (only in blocking mode).
void nrf_drv_twi_uninit ( nrf_drv_twi_t const *const  p_instance)

Function for uninitializing the TWI.

Parameters
[in]p_instanceTWI instance.