This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

was this source incorrect?

/* TWI instance. */

static const nrf_drv_twi_t LTC2499P1 = NRF_DRV_TWI_INSTANCE(0);

static const nrf_drv_twi_t LTC2499P2 = NRF_DRV_TWI_INSTANCE(1);

static void LTC2499P1_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)
		  {
		  }
		  else if(p_event->xfer_desc.type == NRF_DRV_TWI_XFER_TX)
		  {
		  }
		  break;
	   default:
		  break;
	}
}

static void LTC2499P2_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)
		  {
		  }
		  else if(p_event->xfer_desc.type == NRF_DRV_TWI_XFER_TX)
		  {
		  }
		  break;
	   default:
		  break;
	}
}

static void twi_config(void)
{
	ret_code_t err_code;

	const nrf_drv_twi_config_t config1 = {
	  .scl                = LTC2499_DEV2_SCL_PIN,
	  .sda                = LTC2499_DEV2_SDA_PIN,
	  .frequency          = NRF_TWI_FREQ_400K,
	  .interrupt_priority = APP_IRQ_PRIORITY_LOWEST,
	  .clear_bus_init     = true
	};
	
	const nrf_drv_twi_config_t config2 = {
	  .scl                = LTC2499_DEV1_SCL_PIN,
	  .sda                = LTC2499_DEV1_SDA_PIN,
	  .frequency          = NRF_TWI_FREQ_400K,
	  .interrupt_priority = APP_IRQ_PRIORITY_LOWEST,
	  .clear_bus_init     = true
	};
	
	err_code = nrf_drv_twi_init(&LTC2499P1, &config1, LTC2499P1_Handler, NULL);
	APP_ERROR_CHECK(err_code);

	nrf_drv_twi_enable(&LTC2499P1);
	
	err_code = nrf_drv_twi_init(&LTC2499P2, &config2, LTC2499P2_Handler, NULL);
	APP_ERROR_CHECK(err_code);

	nrf_drv_twi_enable(&LTC2499P2);
}

ret_code_t LTC2499_init(void){
	
	ret_code_t ret = NRF_SUCCESS;
	
	const uint8_t config[2] = {
		(0x80 | _BV(LTC2499_CONFIG1_ENABLE) | (0x1F & LTC2499_CONFIG2_60_50HZ_REJ)),
		(_BV(LTC2499_CONFIG2_ENABLE2) | (0x7f & LTC2499_CONFIG2_60_50HZ_REJ))
	};
	
	twi_config();
	ret = nrf_drv_twi_tx(&LTC2499P1,LTC2499_ADDRESS,config,2,false);
	
	if(ret != NRF_SUCCESS)
		return ret;
	
	ret = nrf_drv_twi_tx(&LTC2499P2,LTC2499_ADDRESS,config,2,false);
	
	if(ret != NRF_SUCCESS)
		return ret;
	
	return NRF_SUCCESS;
}

i wanna use two twi master. but Only one twi runs.I hope for help.

Related