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

TWI issue migrating SDK8 -> SDK11

I'm migrating an app from SDK8 to SDK11 and I'm getting errors using TWI to communicate with my IMU (Invensense 9250). I first tried it on a nRF52 DK (Eng B) and then went back to my 51 DK to rule out any hardware issues.

I'm using nrf_drv_twi in a very simple manner on both SDKs (blocking mode for SDK11) and I've tried both TWIM and legacy TWI on SDK11.

My read and write functions need to be called from the Invensense MotionDriver library and look like this on SDK8:

int nrf51_i2c_write(unsigned char slave_addr,
					   unsigned char reg_addr,
					   unsigned char length,
                       unsigned char const *data) 
{
	ret_code_t err_code;

	err_code = nrf_drv_twi_tx(&twi, slave_addr, &reg_addr, sizeof(reg_addr), true);
	APP_ERROR_CHECK(err_code);
	err_code = nrf_drv_twi_tx(&twi, slave_addr, data, length, false);
	APP_ERROR_CHECK(err_code);
    
    return err_code;
}

int nrf51_i2c_read(unsigned char slave_addr,
                    unsigned char reg_addr,
                    unsigned char length,
                    unsigned char *data)
{
	ret_code_t err_code;

	err_code = nrf_drv_twi_tx(&twi, slave_addr, &reg_addr, sizeof(reg_addr), true);
	APP_ERROR_CHECK(err_code);
	err_code = nrf_drv_twi_rx(&twi, slave_addr, data, length, false);
	APP_ERROR_CHECK(err_code);
    
    return err_code;
}

And are virtually identical for the SDK11 version, minus the bool flag param on the nrf_drv_twi_rx call.

I've attached Logic captures for both versions, which show a few successful writes, and then an error trying to write to the compass I2C address. The TWI driver returns an internal error (3).

Thanks for any suggestions.

EDIT: attached a basic example project.

LogicCaptures.zip twitest.zip

Parents
  • The problem is in nrf5x_i2c_write(..) where a repeated tx is used. This does unfortunately not work in SDK11 (but works on SDK 10 and prior). The second nrf_drv_twi_tx(..) call will send out the slave address in addition to the data, which will make the MPU device fail. We have made an internal request to get the repeated tx feature back again. For now you will have to merge the reg_addr and data array and send them with one nrf_drv_twi_tx(..) command.

Reply
  • The problem is in nrf5x_i2c_write(..) where a repeated tx is used. This does unfortunately not work in SDK11 (but works on SDK 10 and prior). The second nrf_drv_twi_tx(..) call will send out the slave address in addition to the data, which will make the MPU device fail. We have made an internal request to get the repeated tx feature back again. For now you will have to merge the reg_addr and data array and send them with one nrf_drv_twi_tx(..) command.

Children
Related