Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

can we use two i2c at the same with different slaves

Hi sir 

We're now working with the nrf52840 DK board, and we want to use two i2c at the same time, but I'm having trouble with one i2c working properly, which means twi1 aren't working.

twi0 is working properly, but i didn't2475.sdk_config.txt get why it is working twi1.

Could you please assist me in resolving the problem?

I'm going to share the sdk config file as well as the twi initialize routines here.

void twi_handler1(nrf_drv_twi_evt_t const * p_event, void * p_context)
{

m_xfer_done1=true;
//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_done1 = true;
// break;
// default:
// break;
//}
}

void twi1_init(void)
{
ret_code_t err_code;

const nrf_drv_twi_config_t twi_extender_config1 = {
.scl = 10,
.sda = 5,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};

// err_code = nrf_drv_twi_init(&m_twi1, &twi_extender_config1, twi_handler1, NULL);
APP_ERROR_CHECK(err_code);

// nrf_drv_twi_enable(&m_twi1);
}


void twi_init (void)
{
ret_code_t err_code;

const nrf_drv_twi_config_t twi_extender_config = {
.scl = ARDUINO_A5_PIN,
.sda = ARDUINO_A4_PIN,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};

// err_code = nrf_drv_twi_init(&m_twi, &twi_extender_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);

// nrf_drv_twi_enable(&m_twi);
}

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;
}
}

Related