TWIM HAL

group nrf_twim_hal

Hardware access layer for managing the TWIM peripheral.

Defines

NRF_TWIM_INST_GET(idx)

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

Parameters:
  • idx[in] TWIM instance index.

Returns:

Pointer to the structure of registers of the TWIM peripheral.

NRF_TWIM_HAS_1000_KHZ_FREQ

Symbol indicating whether 1000 kHz clock frequency is available.

NRF_TWIM_HAS_ARRAY_LIST

Symbol indicating whether EasyDMA array list feature is present.

NRF_TWIM_HAS_DMA_REG

Symbol indicating whether dedicated DMA register is present.

NRF_TWIM_HAS_DMA_TASKS_EVENTS

Symbol indicating whether TWIM DMA tasks and events are present.

NRF_TWIM_DMA_RX_PATTERN_MAX_COUNT

Max number of RX patterns.

Enums

enum nrf_twim_task_t

TWIM tasks.

Values:

enumerator NRF_TWIM_TASK_STARTRX

Start TWI receive sequence.

enumerator NRF_TWIM_TASK_STARTTX

Start TWI transmit sequence.

enumerator NRF_TWIM_TASK_ENABLERXMATCH0

Enable TWI pattern matching functionality for pattern 0.

enumerator NRF_TWIM_TASK_ENABLERXMATCH1

Enable TWI pattern matching functionality for pattern 1.

enumerator NRF_TWIM_TASK_ENABLERXMATCH2

Enable TWI pattern matching functionality for pattern 2.

enumerator NRF_TWIM_TASK_ENABLERXMATCH3

Enable TWI pattern matching functionality for pattern 3.

enumerator NRF_TWIM_TASK_DISABLERXMATCH0

Disable TWI pattern matching functionality for pattern 0.

enumerator NRF_TWIM_TASK_DISABLERXMATCH1

Disable TWI pattern matching functionality for pattern 1.

enumerator NRF_TWIM_TASK_DISABLERXMATCH2

Disable TWI pattern matching functionality for pattern 2.

enumerator NRF_TWIM_TASK_DISABLERXMATCH3

Disable TWI pattern matching functionality for pattern 3.

enumerator NRF_TWIM_TASK_STOP

Stop TWI transaction.

enumerator NRF_TWIM_TASK_SUSPEND

Suspend TWI transaction.

enumerator NRF_TWIM_TASK_RESUME

Resume TWI transaction.

enum nrf_twim_event_t

TWIM events.

Values:

enumerator NRF_TWIM_EVENT_STOPPED

TWI stopped.

enumerator NRF_TWIM_EVENT_ERROR

TWI error.

enumerator NRF_TWIM_EVENT_SUSPENDED

TWI suspended.

enumerator NRF_TWIM_EVENT_ENDRX

Receive sequence finished.

enumerator NRF_TWIM_EVENT_RXSTARTED

Receive sequence started.

enumerator NRF_TWIM_EVENT_RXBUSERROR

Memory bus error occurred during the RX transfer.

enumerator NRF_TWIM_EVENT_RXMATCH0

Pattern match for pattern 0 detected.

enumerator NRF_TWIM_EVENT_RXMATCH1

Pattern match for pattern 1 detected.

enumerator NRF_TWIM_EVENT_RXMATCH2

Pattern match for pattern 2 detected.

enumerator NRF_TWIM_EVENT_RXMATCH3

Pattern match for pattern 3 detected.

enumerator NRF_TWIM_EVENT_ENDTX

Transmit sequence finished.

enumerator NRF_TWIM_EVENT_TXSTARTED

Transmit sequence started.

enumerator NRF_TWIM_EVENT_TXBUSERROR

Memory bus error occurred during the TX transfer.

enumerator NRF_TWIM_EVENT_LASTRX

Byte boundary, starting to receive the last byte.

enumerator NRF_TWIM_EVENT_LASTTX

Byte boundary, starting to transmit the last byte.

enum nrf_twim_short_mask_t

TWIM shortcuts.

Values:

enumerator NRF_TWIM_SHORT_LASTTX_STARTRX_MASK

Shortcut between LASTTX event and STARTRX task.

enumerator NRF_TWIM_SHORT_LASTTX_SUSPEND_MASK

Shortcut between LASTTX event and SUSPEND task.

enumerator NRF_TWIM_SHORT_LASTTX_STOP_MASK

Shortcut between LASTTX event and STOP task.

enumerator NRF_TWIM_SHORT_RXMATCH0_ENABLERXMATCH1_MASK

Shortcut between DMA.RX.MATCH0 event and DMA.RX.ENABLEMATCH1 task.

enumerator NRF_TWIM_SHORT_RXMATCH1_ENABLERXMATCH2_MASK

Shortcut between DMA.RX.MATCH1 event and DMA.RX.ENABLEMATCH2 task.

enumerator NRF_TWIM_SHORT_RXMATCH2_ENABLERXMATCH3_MASK

Shortcut between DMA.RX.MATCH2 event and DMA.RX.ENABLEMATCH0 task.

enumerator NRF_TWIM_SHORT_RXMATCH3_ENABLERXMATCH0_MASK

Shortcut between DMA.RX.MATCH3 event and DMA.RX.ENABLEMATCH1 task.

enumerator NRF_TWIM_SHORT_RXMATCH0_DISABLERXMATCH0_MASK

Shortcut between DMA.RX.MATCH0 event and DMA.RX.DISABLEMATCH0 task.

enumerator NRF_TWIM_SHORT_RXMATCH1_DISABLERXMATCH1_MASK

Shortcut between DMA.RX.MATCH1 event and DMA.RX.DISABLEMATCH1 task.

enumerator NRF_TWIM_SHORT_RXMATCH2_DISABLERXMATCH2_MASK

Shortcut between DMA.RX.MATCH2 event and DMA.RX.DISABLEMATCH2 task.

enumerator NRF_TWIM_SHORT_RXMATCH3_DISABLERXMATCH3_MASK

Shortcut between DMA.RX.MATCH3 event and DMA.RX.DISABLEMATCH3 task.

enumerator NRF_TWIM_SHORT_LASTRX_STARTTX_MASK

Shortcut between LASTRX event and STARTTX task.

enumerator NRF_TWIM_SHORT_LASTRX_STOP_MASK

Shortcut between LASTRX event and STOP task.

enumerator NRF_TWIM_ALL_SHORTS_MASK

All TWIM shortcuts.

enum nrf_twim_int_mask_t

TWIM interrupts.

Values:

enumerator NRF_TWIM_INT_STOPPED_MASK

Interrupt on STOPPED event.

enumerator NRF_TWIM_INT_ERROR_MASK

Interrupt on ERROR event.

enumerator NRF_TWIM_INT_SUSPENDED_MASK

Interrupt on SUSPENDED event.

enumerator NRF_TWIM_INT_RXSTARTED_MASK

Interrupt on RXSTARTED event.

enumerator NRF_TWIM_INT_TXSTARTED_MASK

Interrupt on TXSTARTED event.

enumerator NRF_TWIM_INT_ENDRX_MASK

Interrupt on DMA.RX.END event.

enumerator NRF_TWIM_INT_RXREADY_MASK

Interrupt on DMA.RX.READY event.

enumerator NRF_TWIM_INT_RXBUSERROR_MASK

Interrupt on DMA.RX.BUSERROR event.

enumerator NRF_TWIM_INT_RXMATCH0_MASK

Interrupt on DMA.RX.MATCH0 event.

enumerator NRF_TWIM_INT_RXMATCH1_MASK

Interrupt on DMA.RX.MATCH1 event.

enumerator NRF_TWIM_INT_RXMATCH2_MASK

Interrupt on DMA.RX.MATCH2 event.

enumerator NRF_TWIM_INT_RXMATCH3_MASK

Interrupt on DMA.RX.MATCH3 event.

enumerator NRF_TWIM_INT_ENDTX_MASK

Interrupt on DMA.TX.END event.

enumerator NRF_TWIM_INT_TXREADY_MASK

Interrupt on DMA.TX.READY event.

enumerator NRF_TWIM_INT_TXBUSERROR_MASK

Interrupt on DMA.TX.BUSERROR event.

enumerator NRF_TWIM_INT_LASTRX_MASK

Interrupt on LASTRX event.

enumerator NRF_TWIM_INT_LASTTX_MASK

Interrupt on LASTTX event.

enumerator NRF_TWIM_ALL_INTS_MASK

All TWIM interrupts.

enum nrf_twim_frequency_t

TWIM master clock frequency.

Values:

enumerator NRF_TWIM_FREQ_100K

100 kbps.

enumerator NRF_TWIM_FREQ_250K

250 kbps.

enumerator NRF_TWIM_FREQ_400K

400 kbps.

enumerator NRF_TWIM_FREQ_1000K

1000 kbps.

enum nrf_twim_error_t

TWIM error source.

Values:

enumerator NRF_TWIM_ERROR_ADDRESS_NACK

NACK received after sending the address.

enumerator NRF_TWIM_ERROR_DATA_NACK

NACK received after sending a data byte.

enumerator NRF_TWIM_ERROR_OVERRUN

Overrun error.

A new byte was received before the previous byte was handled by peripheral. (previous data is lost).

Functions

NRF_STATIC_INLINE void nrf_twim_task_trigger(NRF_TWIM_Type *p_reg, nrf_twim_task_t task)

Function for activating the specified TWIM 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_twim_task_address_get(NRF_TWIM_Type const *p_reg, nrf_twim_task_t task)

Function for getting the address of the specified TWIM 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_twim_event_clear(NRF_TWIM_Type *p_reg, nrf_twim_event_t event)

Function for clearing the specified TWIM event.

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

  • event[in] Event to clear.

NRF_STATIC_INLINE bool nrf_twim_event_check(NRF_TWIM_Type const *p_reg, nrf_twim_event_t event)

Function for retrieving the state of the TWIM 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_twim_event_address_get(NRF_TWIM_Type const *p_reg, nrf_twim_event_t event)

Function for getting the address of the specified TWIM 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_twim_shorts_enable(NRF_TWIM_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_twim_shorts_disable(NRF_TWIM_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_twim_int_enable(NRF_TWIM_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_twim_int_disable(NRF_TWIM_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_twim_int_enable_check(NRF_TWIM_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_twim_subscribe_set(NRF_TWIM_Type *p_reg, nrf_twim_task_t task, uint8_t channel)

Function for setting the subscribe configuration for a given TWIM task.

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

  • task[in] Task for which to set the configuration.

  • channel[in] Channel through which to subscribe events.

NRF_STATIC_INLINE void nrf_twim_subscribe_clear(NRF_TWIM_Type *p_reg, nrf_twim_task_t task)

Function for clearing the subscribe configuration for a given TWIM task.

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

  • task[in] Task for which to clear the configuration.

NRF_STATIC_INLINE void nrf_twim_publish_set(NRF_TWIM_Type *p_reg, nrf_twim_event_t event, uint8_t channel)

Function for setting the publish configuration for a given TWIM event.

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

  • event[in] Event for which to set the configuration.

  • channel[in] Channel through which to publish the event.

NRF_STATIC_INLINE void nrf_twim_publish_clear(NRF_TWIM_Type *p_reg, nrf_twim_event_t event)

Function for clearing the publish configuration for a given TWIM event.

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

  • event[in] Event for which to clear the configuration.

NRF_STATIC_INLINE void nrf_twim_enable(NRF_TWIM_Type *p_reg)

Function for enabling the TWIM peripheral.

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

NRF_STATIC_INLINE void nrf_twim_disable(NRF_TWIM_Type *p_reg)

Function for disabling the TWIM peripheral.

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

NRF_STATIC_INLINE void nrf_twim_pins_set(NRF_TWIM_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_twim_scl_pin_get(NRF_TWIM_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_twim_sda_pin_get(NRF_TWIM_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_twim_frequency_set(NRF_TWIM_Type *p_reg, nrf_twim_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_twim_errorsrc_get_and_clear(NRF_TWIM_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_twim_address_set(NRF_TWIM_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_twim_address_get(NRF_TWIM_Type const *p_reg)

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

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

Returns:

Address to be used in TWI transfers.

NRF_STATIC_INLINE void nrf_twim_tx_buffer_set(NRF_TWIM_Type *p_reg, uint8_t const *p_buffer, size_t length)

Function for setting the transmit buffer.

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

  • p_buffer[in] Pointer to the buffer with data to send.

  • length[in] Maximum number of data bytes to transmit.

NRF_STATIC_INLINE void nrf_twim_rx_buffer_set(NRF_TWIM_Type *p_reg, uint8_t *p_buffer, size_t length)

Function for setting the receive buffer.

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

  • p_buffer[in] Pointer to the buffer for received data.

  • length[in] Maximum number of data bytes to receive.

NRF_STATIC_INLINE void nrf_twim_shorts_set(NRF_TWIM_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.

NRF_STATIC_INLINE uint32_t nrf_twim_shorts_get(NRF_TWIM_Type const *p_reg)

Function for getting the shortcut setting.

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

Returns:

Current shortcut configuration.

NRF_STATIC_INLINE size_t nrf_twim_txd_amount_get(NRF_TWIM_Type const *p_reg)

Function for getting the amount of transmitted bytes.

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

Returns:

Amount of transmitted bytes.

NRF_STATIC_INLINE size_t nrf_twim_rxd_amount_get(NRF_TWIM_Type const *p_reg)

Function for getting the amount of received bytes.

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

Returns:

Amount of received bytes.

NRF_STATIC_INLINE void nrf_twim_tx_list_enable(NRF_TWIM_Type *p_reg)

Function for enabling the TX list feature.

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

NRF_STATIC_INLINE void nrf_twim_tx_list_disable(NRF_TWIM_Type *p_reg)

Function for disabling the TX list feature.

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

NRF_STATIC_INLINE void nrf_twim_rx_list_enable(NRF_TWIM_Type *p_reg)

Function for enabling the RX list feature.

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

NRF_STATIC_INLINE void nrf_twim_rx_list_disable(NRF_TWIM_Type *p_reg)

Function for disabling the RX list feature.

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

NRF_STATIC_INLINE void nrf_twim_rx_pattern_match_enable_set(NRF_TWIM_Type *p_reg, uint8_t index, bool enable)

Function for enabling individual pattern match filters.

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

  • index[in] Index of pattern match filter.

  • enable[in] True if pattern match filter is to be enabled, false otherwise.

NRF_STATIC_INLINE bool nrf_twim_rx_pattern_match_enable_check(NRF_TWIM_Type const *p_reg, uint8_t index)

Function for checking if the specified pattern match filter is enabled.

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

  • index[in] Index of pattern match filter.

Return values:
  • true – Pattern match filter is enabled.

  • false – Pattern match filter is disabled.

NRF_STATIC_INLINE void nrf_twim_rx_pattern_match_one_shot_enable(NRF_TWIM_Type *p_reg, uint8_t index)

Function for enabling one-shot operation for the specified match filter.

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

  • index[in] Index of pattern match filter.

NRF_STATIC_INLINE void nrf_twim_rx_pattern_match_one_shot_disable(NRF_TWIM_Type *p_reg, uint8_t index)

Function for disabling one-shot operation for the specified match filter.

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

  • index[in] Index of pattern match filter.

NRF_STATIC_INLINE bool nrf_twim_rx_pattern_match_one_shot_check(NRF_TWIM_Type const *p_reg, uint8_t index)

Function for checking if specified pattern match filter is configured as one-shot.

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

  • index[in] Index of pattern match filter.

Return values:
  • true – Pattern match filter is configured as one-shot.

  • false – Pattern match filter is configured as continuous.

NRF_STATIC_INLINE void nrf_twim_rx_pattern_match_candidate_set(NRF_TWIM_Type *p_reg, uint8_t index, uint32_t pattern)

Function for setting the pattern to be looked for by the specified match filter.

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

  • index[in] Index of pattern match filter.

  • pattern[in] Pattern to be looked for. Match will trigger the corresponding event, if enabled.

NRF_STATIC_INLINE uint32_t nrf_twim_rx_pattern_match_candidate_get(NRF_TWIM_Type const *p_reg, uint8_t index)

Function for getting the pattern that the specified match filter is looking for.

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

  • index[in] Index of pattern match filter.

Returns:

Pattern that the specified match filter is looking for.