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

How to use TWI xfer of TXRX

Hello,

nRF51822 SDKv11 Kail 5.18 SD130

I have a pcb that has a sensor with I2C. I made a project that based on the sample of "twi_sensor", and I can read the sensor data. The project sequence is like this.

  1. send tx with no sotp condition,

  2. tx inturrupt fire

  3. send rx.

Then, I found a function "nrf_drv_twi_xfer" and it seems I could do same thing with less code amount. Then I made following code but I could not read the value. There is no twi error and the value is always "0". It's for sure the address or some setting is not wrong.

static const nrf_drv_twi_t twi = NRF_DRV_TWI_INSTANCE(0);

void twi_init (void)
{

  ret_code_t err_code;
  
  const nrf_drv_twi_config_t twi_config = {
       .scl                = SCL_PIN,
       .sda                = SDA_PIN,
       .frequency          = NRF_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH
  };
    
  err_code = nrf_drv_twi_init(&twi, &twi_config, NULL, NULL);

  APP_ERROR_CHECK(err_code);

  nrf_drv_twi_enable(&twi);

}

int main(void)
{
...

  uint8_t reg = MPU6500_axh_adr;
  nrf_drv_twi_xfer_desc_t xfer = NRF_DRV_TWI_XFER_DESC_TXRX(MPU6500_ADDR,
                                                &reg,               
                                                sizeof(reg)	,																
                                                (uint8_t*)&m_samples,
                                                sizeof(m_samples));

  uint32_t flags = NRF_DRV_TWI_FLAG_TX_NO_STOP;

  err_code = nrf_drv_twi_xfer(&twi, &xfer, flags);

  if(err_code  != NRF_SUCCESS){
    SEGGER_RTT_printf(0, "OK\r\n");
  }else{
    SEGGER_RTT_printf(0, "NG\r\n");
  }

...
}
Parents
  • This is the exact same thing I'm trying to do, except I use SDK 14.1. Same result. When checking on the I2C bus, the slave actually sends zeroes or the master doesn't switch off its transmitter, keeping it low for some reason. Were you able to find the cause of this behavior?

Reply
  • This is the exact same thing I'm trying to do, except I use SDK 14.1. Same result. When checking on the I2C bus, the slave actually sends zeroes or the master doesn't switch off its transmitter, keeping it low for some reason. Were you able to find the cause of this behavior?

Children
No Data