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

  • Sorry, not sure how that got messed up. Added new attachment that compiles properly (template_pca10040 project file).

  • 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.

  • I modified the code as you suggested and it solved the problem. Thank you for the help!

  • @kirkus could you please tell me how did you modified the code?

  • A little update on the issue: It turns out that the root cause is a hardware limitation in nRF52. As opposed to the nRF51 the nRF52 is not capable of sending TX transmissions back-to-back without a repeated start and new slave address. The SDK team chose to make a consistent TWI driver with the same feature set on both nRF51 and nRF52 in SDK 11. So removing the feature from the driver was a conscious, although inconvenient, choice and it will require a redesign of the TWI hardware in nRF52 to bring it back. When or if that will happen is impossible to say. In the meantime the only option is to use nRF51 and SDK <= 10.

Related