This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to implement two TWI instances

Hello,

I am having difficulty using a single TWI to support a DAC (MCP4725) and IMU (BNO055). 

I am using nRF52 DK, and SDK 14.3 with the SEGGER IDE.  The DAC is running on a timer with samples being loaded every 200 micro seconds.  The IMU is running on the same TWI bus and I am collecting 3 data samples (2 bytes each) every 20 milliseconds.  The data is being piped over BLE at 50 samples per second (packing 2 sets of samples in a single 20 byte packet every 40 milliseconds). If I output a triangular waveform, I get an artifact every 20 milliseconds with a varying time for the length of the artifact (see the attached images below).  

My plan is to split the processing so the DAC is on one twi and the IMU on a second TWI bus.  If I do this, what pins can be used for the second TWI if I use the default pins for the first TWI?  Below are my initialization functions:

void dac_twi_init (void)
{
ret_code_t err_code;

const nrf_drv_twi_config_t twi_mcp4725_config = {
.scl = ARDUINO_SCL_PIN,
.sda = ARDUINO_SDA_PIN,
.frequency = NRF_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};

err_code = nrf_drv_twi_init(&m_dac, &twi_mcp4725_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);


nrf_drv_twi_enable(&m_dac);
}

void imu_twi_init (void)
{
ret_code_t err_code;
const nrf_drv_twi_config_t twi_bno055_config = {
.scl = 10,
.sda = 9,
.frequency = NRF_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};

err_code = nrf_drv_twi_init(&m_imu, &twi_bno055_config, twi_bno055_handler, NULL);
APP_ERROR_CHECK(err_code);

nrf_drv_twi_enable(&m_imu);
}

As you can see, the amount of corruption in the waveform varies.  Sometimes it is very obvious and sometimes almost undetectable.  Occurring every 20 mS indicates that the transfer of data from the IMU is impacting the ability for the DAC outputs to continue at the 200 microsecond intervals (they get delayed and thus the horizontal corruption in the DAC output).

My questions are:

1. Do you think using 2 TWIs will solve the issue?

2. Are Pins 9 and 10 "legal" pins to use for the second TWI?

3. Does my initialization above look correct?

4. Is there a possibility of other causes of the corruption and what are they?

Thanks in advance for your help.  This medical project is in the final prototype stages and "clean" DAC waveforms are absolutely necessary.
 

Related