TWI peripheral driver.
More...
|
#define | NRFX_TWI_INSTANCE(id) |
| Macro for creating a TWI master driver instance. More...
|
|
#define | NRFX_TWI_DEFAULT_CONFIG |
| TWI master driver instance default configuration. More...
|
|
#define | NRFX_TWI_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) |
|
#define | NRFX_TWI_FLAG_TX_NO_STOP (1UL << 5) |
|
#define | NRFX_TWI_XFER_DESC_TX(addr, p_data, length) |
| Macro for setting the TX transfer descriptor. More...
|
|
#define | NRFX_TWI_XFER_DESC_RX(addr, p_data, length) |
| Macro for setting the RX transfer descriptor. More...
|
|
#define | NRFX_TWI_XFER_DESC_TXRX(addr, p_tx, tx_len, p_rx, rx_len) |
| Macro for setting the TXRX transfer descriptor. More...
|
|
#define | NRFX_TWI_XFER_DESC_TXTX(addr, p_tx, tx_len, p_tx2, tx_len2) |
| Macro for setting the TXTX transfer descriptor. More...
|
|
|
nrfx_err_t | nrfx_twi_init (nrfx_twi_t const *p_instance, nrfx_twi_config_t const *p_config, nrfx_twi_evt_handler_t event_handler, void *p_context) |
| Function for initializing the TWI driver instance. More...
|
|
void | nrfx_twi_uninit (nrfx_twi_t const *p_instance) |
| Function for uninitializing the TWI instance. More...
|
|
void | nrfx_twi_enable (nrfx_twi_t const *p_instance) |
| Function for enabling the TWI instance. More...
|
|
void | nrfx_twi_disable (nrfx_twi_t const *p_instance) |
| Function for disabling the TWI instance. More...
|
|
nrfx_err_t | nrfx_twi_tx (nrfx_twi_t const *p_instance, uint8_t address, uint8_t const *p_data, size_t length, bool no_stop) |
| Function for sending data to a TWI slave. More...
|
|
nrfx_err_t | nrfx_twi_rx (nrfx_twi_t const *p_instance, uint8_t address, uint8_t *p_data, size_t length) |
| Function for reading data from a TWI slave. More...
|
|
nrfx_err_t | nrfx_twi_xfer (nrfx_twi_t const *p_instance, nrfx_twi_xfer_desc_t const *p_xfer_desc, uint32_t flags) |
| Function for preparing a TWI transfer. More...
|
|
bool | nrfx_twi_is_busy (nrfx_twi_t const *p_instance) |
| Function for checking the TWI driver state. More...
|
|
size_t | nrfx_twi_data_count_get (nrfx_twi_t const *const p_instance) |
| Function for getting the transferred data count. More...
|
|
uint32_t | nrfx_twi_stopped_event_get (nrfx_twi_t const *p_instance) |
| Function for returning the address of a STOPPED TWI event. More...
|
|
void | nrfx_twi_0_irq_handler (void) |
|
void | nrfx_twi_1_irq_handler (void) |
|
TWI peripheral driver.
#define NRFX_TWI_DEFAULT_CONFIG |
Value:{ \
.scl = 31, \
.sda = 31, \
}
TWI master driver instance default configuration.
#define NRFX_TWI_FLAG_NO_XFER_EVT_HANDLER (1UL << 2) |
Interrupt after each transfer is suppressed, and the event handler is not called.
#define NRFX_TWI_FLAG_TX_NO_STOP (1UL << 5) |
Flag indicating that the TX transfer will not end with a stop condition.
#define NRFX_TWI_INSTANCE |
( |
|
id | ) |
|
Value:
Macro for creating a TWI master driver instance.
#define NRFX_TWI_XFER_DESC_RX |
( |
|
addr, |
|
|
|
p_data, |
|
|
|
length |
|
) |
| |
Value:{ \
.address = addr, \
.primary_length = length, \
.p_primary_buf = p_data, \
}
Macro for setting the RX transfer descriptor.
#define NRFX_TWI_XFER_DESC_TX |
( |
|
addr, |
|
|
|
p_data, |
|
|
|
length |
|
) |
| |
Value:{ \
.address = addr, \
.primary_length = length, \
.p_primary_buf = p_data, \
}
Macro for setting the TX transfer descriptor.
#define NRFX_TWI_XFER_DESC_TXRX |
( |
|
addr, |
|
|
|
p_tx, |
|
|
|
tx_len, |
|
|
|
p_rx, |
|
|
|
rx_len |
|
) |
| |
Value:{ \
.address = addr, \
.primary_length = tx_len, \
.secondary_length = rx_len, \
.p_primary_buf = p_tx, \
.p_secondary_buf = p_rx, \
}
Macro for setting the TXRX transfer descriptor.
#define NRFX_TWI_XFER_DESC_TXTX |
( |
|
addr, |
|
|
|
p_tx, |
|
|
|
tx_len, |
|
|
|
p_tx2, |
|
|
|
tx_len2 |
|
) |
| |
Value:{ \
.address = addr, \
.primary_length = tx_len, \
.secondary_length = tx_len2, \
.p_primary_buf = p_tx, \
.p_secondary_buf = p_tx2, \
}
Macro for setting the TXTX transfer descriptor.
TWI master driver event types.
Enumerator |
---|
NRFX_TWI_EVT_DONE |
Transfer completed event.
|
NRFX_TWI_EVT_ADDRESS_NACK |
Error event: NACK received after sending the address.
|
NRFX_TWI_EVT_DATA_NACK |
Error event: NACK received after sending a data byte.
|
TWI master driver transfer types.
Enumerator |
---|
NRFX_TWI_XFER_TX |
TX transfer.
|
NRFX_TWI_XFER_RX |
RX transfer.
|
NRFX_TWI_XFER_TXRX |
TX transfer followed by RX transfer with repeated start.
|
NRFX_TWI_XFER_TXTX |
TX transfer followed by TX transfer with repeated start.
|
size_t nrfx_twi_data_count_get |
( |
nrfx_twi_t const *const |
p_instance | ) |
|
Function for getting the transferred data count.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
- Returns
- Data count.
void nrfx_twi_disable |
( |
nrfx_twi_t const * |
p_instance | ) |
|
Function for disabling the TWI instance.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
void nrfx_twi_enable |
( |
nrfx_twi_t const * |
p_instance | ) |
|
Function for enabling the TWI instance.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
Function for initializing the TWI driver instance.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
[in] | p_config | Pointer to the structure with 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. |
- Return values
-
NRFX_SUCCESS | If initialization was successful. |
NRFX_ERROR_INVALID_STATE | If the driver is in invalid state. |
NRFX_ERROR_BUSY | If 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_twi_is_busy |
( |
nrfx_twi_t const * |
p_instance | ) |
|
Function for checking the TWI driver state.
- Parameters
-
[in] | p_instance | TWI instance. |
- Return values
-
true | If the TWI driver is currently busy performing a transfer. |
false | If the TWI driver is ready for a new transfer. |
nrfx_err_t nrfx_twi_rx |
( |
nrfx_twi_t const * |
p_instance, |
|
|
uint8_t |
address, |
|
|
uint8_t * |
p_data, |
|
|
size_t |
length |
|
) |
| |
Function for reading data from a TWI slave.
The transmission will be stopped when an error occurs. If a transfer is ongoing, the function returns the error code NRFX_ERROR_BUSY.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
[in] | address | Address of a specific slave device (only 7 LSB). |
[in] | p_data | Pointer to a receive buffer. |
[in] | length | Number of bytes to be received. |
- Return values
-
NRFX_SUCCESS | If the procedure was successful. |
NRFX_ERROR_BUSY | If the driver is not ready for a new transfer. |
NRFX_ERROR_INTERNAL | If an error was detected by hardware. |
NRFX_ERROR_DRV_TWI_ERR_OVERRUN | If the unread data was replaced by new data |
NRFX_ERROR_DRV_TWI_ERR_ANACK | If NACK received after sending the address in polling mode. |
NRFX_ERROR_DRV_TWI_ERR_DNACK | If NACK received after sending a data byte in polling mode. |
uint32_t nrfx_twi_stopped_event_get |
( |
nrfx_twi_t const * |
p_instance | ) |
|
Function for returning the address of a STOPPED TWI event.
A STOPPED event can be used to detect the end of a transfer if the NRFX_TWI_FLAG_NO_XFER_EVT_HANDLER option is used.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
- Returns
- STOPPED event address.
nrfx_err_t nrfx_twi_tx |
( |
nrfx_twi_t const * |
p_instance, |
|
|
uint8_t |
address, |
|
|
uint8_t const * |
p_data, |
|
|
size_t |
length, |
|
|
bool |
no_stop |
|
) |
| |
Function for sending data to a TWI slave.
The transmission will be stopped when an error occurs. If a transfer is ongoing, the function returns the error code NRFX_ERROR_BUSY.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
[in] | address | Address of a specific slave device (only 7 LSB). |
[in] | p_data | Pointer to a transmit buffer. |
[in] | length | Number of bytes to send. |
[in] | no_stop | If set, the stop condition is not generated on the bus after the transfer has completed successfully (allowing for a repeated start in the next transfer). |
- Return values
-
NRFX_SUCCESS | If the procedure was successful. |
NRFX_ERROR_BUSY | If the driver is not ready for a new transfer. |
NRFX_ERROR_INTERNAL | If an error was detected by hardware. |
NRFX_ERROR_DRV_TWI_ERR_ANACK | If NACK received after sending the address in polling mode. |
NRFX_ERROR_DRV_TWI_ERR_DNACK | If NACK received after sending a data byte in polling mode. |
void nrfx_twi_uninit |
( |
nrfx_twi_t const * |
p_instance | ) |
|
Function for uninitializing the TWI instance.
- Parameters
-
[in] | p_instance | Pointer to the driver instance structure. |
Function for preparing a TWI transfer.
The following transfer types can be configured (nrfx_twi_xfer_desc_t::type):
- Note
- TXRX and TXTX transfers are supported only in non-blocking mode.
Additional options are provided using the flags parameter:
- Note
- Some flag combinations are invalid:
- Parameters
-
[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). |
- Return values
-
NRFX_SUCCESS | If the procedure was successful. |
NRFX_ERROR_BUSY | If the driver is not ready for a new transfer. |
NRFX_ERROR_NOT_SUPPORTED | If the provided parameters are not supported. |
NRFX_ERROR_INTERNAL | If an error was detected by hardware. |
NRFX_ERROR_DRV_TWI_ERR_OVERRUN | If the unread data was replaced by new data (TXRX and RX) |
NRFX_ERROR_DRV_TWI_ERR_ANACK | If NACK received after sending the address. |
NRFX_ERROR_DRV_TWI_ERR_DNACK | If NACK received after sending a data byte. |