/* TWI instance ID. */
#define TWI_INSTANCE_ID 0
/* Indicates if operation on TWI has ended. */
static volatile bool m_xfer_done = false;
/* TWI instance. */
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
/**
* @brief TWI events handler.
*/
void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
switch (p_event->type)
{
case NRF_DRV_TWI_EVT_DONE:
if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
{
// data_handler(m_sample);
}
m_xfer_done = true;
break;
default:
break;
}
}
void twi_config(void)
{
ret_code_t err_code;
const nrf_drv_twi_config_t twi_mma865x_config =
{
.scl = NRFX_SCL_PIN,
.sda = NRFX_SDA_PIN,
.frequency = NRF_DRV_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = true
};
err_code = nrf_drv_twi_init(&m_twi, &twi_mma865x_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi);
}
包括文件nrf_drv_twi.c,nrfx_twi.c,nrfx_twim.c文件;打开宏NRFX_PRS_ENABLE,NRFX_TWI_NEBALE,NRFX_TWIM_NEBALE,
TWI_NEBALE