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

nRF52840 SDK16 - TWI Driver

Hi everyone, I am using TWI driver to communicate with I2C. I have write the following I2C read function. 

/* TWI instance. */
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

int8_t Acc_i2c_Read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) {
  int8_t rslt = 0;
  
  rslt = nrf_drv_twi_tx(&m_twi, dev_id, &reg_addr, 1, false); 
  APP_ERROR_CHECK(rslt);

  if (rslt == 0) {
    rslt = nrf_drv_twi_rx(&m_twi, dev_id, reg_data, len);
  }
  return rslt;
}

Now I want to write a second I2C function with some modifications. I will use the same TWI instance for it? For example:

int8_t My_I2C_Second(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) {
  
  // Some modifications....
  
  int8_t rslt = 0;
  
  rslt = nrf_drv_twi_tx(&m_twi, dev_id, &reg_addr, 1, false); 
  APP_ERROR_CHECK(rslt);

  if (rslt == 0) {
    rslt = nrf_drv_twi_rx(&m_twi, dev_id, reg_data, len);
  }
  return rslt;
}

Thanks in advance

Nick

Parents Reply Children
Related