TWI HAL

group nrf_twi_hal

Hardware access layer for managing the TWI peripheral.

Defines

NRF_TWI_INST_GET(idx)

Macro getting pointer to the structure of registers of the TWI peripheral.

Parameters:
  • idx[in] TWI instance index.

Returns:

Pointer to the structure of registers of the TWI peripheral.

Enums

enum nrf_twi_task_t

TWI tasks.

Values:

enumerator NRF_TWI_TASK_STARTRX

Start TWI receive sequence.

enumerator NRF_TWI_TASK_STARTTX

Start TWI transmit sequence.

enumerator NRF_TWI_TASK_STOP

Stop TWI transaction.

enumerator NRF_TWI_TASK_SUSPEND

Suspend TWI transaction.

enumerator NRF_TWI_TASK_RESUME

Resume TWI transaction.

enum nrf_twi_event_t

TWI events.

Values:

enumerator NRF_TWI_EVENT_STOPPED

TWI stopped.

enumerator NRF_TWI_EVENT_RXDREADY

TWI RXD byte received.

enumerator NRF_TWI_EVENT_TXDSENT

TWI TXD byte sent.

enumerator NRF_TWI_EVENT_ERROR

TWI error.

enumerator NRF_TWI_EVENT_BB

TWI byte boundary, generated before each byte that is sent or received.

enumerator NRF_TWI_EVENT_SUSPENDED

TWI entered the suspended state.

enum nrf_twi_short_mask_t

TWI shortcuts.

Values:

enumerator NRF_TWI_SHORT_BB_SUSPEND_MASK

Shortcut between BB event and SUSPEND task.

enumerator NRF_TWI_SHORT_BB_STOP_MASK

Shortcut between BB event and STOP task.

enumerator NRF_TWI_ALL_SHORTS_MASK

All TWI shortcuts.

enum nrf_twi_int_mask_t

TWI interrupts.

Values:

enumerator NRF_TWI_INT_STOPPED_MASK

Interrupt on STOPPED event.

enumerator NRF_TWI_INT_RXDREADY_MASK

Interrupt on RXDREADY event.

enumerator NRF_TWI_INT_TXDSENT_MASK

Interrupt on TXDSENT event.

enumerator NRF_TWI_INT_ERROR_MASK

Interrupt on ERROR event.

enumerator NRF_TWI_INT_BB_MASK

Interrupt on BB event.

enumerator NRF_TWI_INT_SUSPENDED_MASK

Interrupt on SUSPENDED event.

enumerator NRF_TWI_ALL_INTS_MASK

All TWI interrupts.

enum nrf_twi_error_t

TWI error source.

Values:

enumerator NRF_TWI_ERROR_ADDRESS_NACK

NACK received after sending the address.

enumerator NRF_TWI_ERROR_DATA_NACK

NACK received after sending a data byte.

enumerator NRF_TWI_ERROR_OVERRUN

Overrun error.

A new byte was received before the previous byte was read from the RXD register (previous data is lost).

enum nrf_twi_frequency_t

TWI master clock frequency.

Values:

enumerator NRF_TWI_FREQ_100K

100 kbps.

enumerator NRF_TWI_FREQ_250K

250 kbps.

enumerator NRF_TWI_FREQ_400K

400 kbps.

Functions

NRF_STATIC_INLINE void nrf_twi_task_trigger(NRF_TWI_Type *p_reg, nrf_twi_task_t task)

Function for activating the specified TWI task.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] Task to be activated.

NRF_STATIC_INLINE uint32_t nrf_twi_task_address_get(NRF_TWI_Type const *p_reg, nrf_twi_task_t task)

Function for getting the address of the specified TWI task register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] The specified task.

Returns:

Address of the specified task register.

NRF_STATIC_INLINE void nrf_twi_event_clear(NRF_TWI_Type *p_reg, nrf_twi_event_t event)

Function for clearing the specified TWI event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to clear.

NRF_STATIC_INLINE bool nrf_twi_event_check(NRF_TWI_Type const *p_reg, nrf_twi_event_t event)

Function for retrieving the state of the TWI event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to be checked.

Return values:
  • true – The event has been generated.

  • false – The event has not been generated.

NRF_STATIC_INLINE uint32_t nrf_twi_event_address_get(NRF_TWI_Type const *p_reg, nrf_twi_event_t event)

Function for getting the address of the specified TWI event register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] The specified event.

Returns:

Address of the specified event register.

NRF_STATIC_INLINE void nrf_twi_shorts_enable(NRF_TWI_Type *p_reg, uint32_t mask)

Function for enabling the specified shortcuts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Shortcuts to be enabled.

NRF_STATIC_INLINE void nrf_twi_shorts_disable(NRF_TWI_Type *p_reg, uint32_t mask)

Function for disabling the specified shortcuts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Shortcuts to be disabled.

NRF_STATIC_INLINE void nrf_twi_int_enable(NRF_TWI_Type *p_reg, uint32_t mask)

Function for enabling the specified interrupts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be enabled.

NRF_STATIC_INLINE void nrf_twi_int_disable(NRF_TWI_Type *p_reg, uint32_t mask)

Function for disabling the specified interrupts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be disabled.

NRF_STATIC_INLINE uint32_t nrf_twi_int_enable_check(NRF_TWI_Type const *p_reg, uint32_t mask)

Function for checking if the specified interrupts are enabled.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be checked.

Returns:

Mask of enabled interrupts.

NRF_STATIC_INLINE void nrf_twi_enable(NRF_TWI_Type *p_reg)

Function for enabling the TWI peripheral.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_twi_disable(NRF_TWI_Type *p_reg)

Function for disabling the TWI peripheral.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_twi_pins_set(NRF_TWI_Type *p_reg, uint32_t scl_pin, uint32_t sda_pin)

Function for configuring TWI pins.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • scl_pin[in] SCL pin number.

  • sda_pin[in] SDA pin number.

NRF_STATIC_INLINE uint32_t nrf_twi_scl_pin_get(NRF_TWI_Type const *p_reg)

Function for retrieving the SCL pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

SCL pin selection.

NRF_STATIC_INLINE uint32_t nrf_twi_sda_pin_get(NRF_TWI_Type const *p_reg)

Function for retrieving the SDA pin selection.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

SDA pin selection.

NRF_STATIC_INLINE void nrf_twi_frequency_set(NRF_TWI_Type *p_reg, nrf_twi_frequency_t frequency)

Function for setting the TWI master clock frequency.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • frequency[in] TWI frequency.

NRF_STATIC_INLINE uint32_t nrf_twi_errorsrc_get_and_clear(NRF_TWI_Type *p_reg)

Function for checking the TWI error source.

The error flags are cleared after reading.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Mask with error source flags.

NRF_STATIC_INLINE void nrf_twi_address_set(NRF_TWI_Type *p_reg, uint8_t address)

Function for setting the address to be used in TWI transfers.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • address[in] Address to be used in transfers.

NRF_STATIC_INLINE uint8_t nrf_twi_rxd_get(NRF_TWI_Type const *p_reg)

Function for reading data received by TWI.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

Received data.

NRF_STATIC_INLINE void nrf_twi_txd_set(NRF_TWI_Type *p_reg, uint8_t data)

Function for writing data to be transmitted by TWI.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • data[in] Data to be transmitted.

NRF_STATIC_INLINE void nrf_twi_shorts_set(NRF_TWI_Type *p_reg, uint32_t mask)

Function for setting the specified shortcuts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Shortcuts to be set.