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

nRF52840 I2C burst write function issues

I need to burst write the DMP library into the mpu6050 but not succeed.

The following is the function that I've been using to burst write.

 

uint32_t nrf_drv_mpu_write_registers(uint8_t reg, uint8_t * p_data, uint32_t length)
{
    // This burst write function is not optimal and needs improvement.
    // The new SDK 11 TWI driver is not able to do two transmits without repeating the ADDRESS + Write bit byte
    uint32_t err_code;
    uint32_t timeout = MPU_TWI_TIMEOUT;

    // Merging MPU register address and p_data into one buffer.
    merge_register_and_data(twi_tx_buffer, reg, p_data, length);

    // Setting up transfer
    nrf_drv_twi_xfer_desc_t xfer_desc;
    xfer_desc.address = MPU_ADDRESS;
    xfer_desc.type = NRF_DRV_TWI_XFER_TX;
    xfer_desc.primary_length = length + 1;
    xfer_desc.p_primary_buf = twi_tx_buffer;

    // Transferring
    err_code = nrf_drv_twi_xfer(&m_twi_instance, &xfer_desc, 0);

    while((!twi_tx_done) && --timeout);
    if(!timeout) return NRF_ERROR_TIMEOUT;
    twi_tx_done = false;

    return err_code;
}

I have researched on the following function:

bool i2cdev_writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t* data) {
	
	/*
	if (NRF_SUCCESS!=nrf_drv_twi_tx(&m_twi,devAddr,&regAddr,1,true))
		return false;
	return NRF_SUCCESS==nrf_drv_twi_tx(&m_twi,devAddr,data,length,false);
	*/
	
	//TODO: This could be improved...
	uint8_t buffer[32];
	buffer[0] = regAddr;
	uint8_t i = 1;
	while(i < (length + 1))
		buffer[i++] = *data++;
	
	return NRF_SUCCESS==nrf_drv_twi_tx(&m_twi,devAddr,buffer,length+1,false);
}

I see this function is for continuous write of bytes but to consecutive addresses. 

Can I do the burst write by changing the no_stop parameter to true. The attached photo is the definition for the nrf_drv_twi_tx function

Parents
  • Hello,

    Can you please check out this github repository:

    https://github.com/Martinsbl/nrf5-mpu-examples

    There are a few examples there that uses the sensor that you mentioned, the MPU6050. I have tested the nrf5-ble-mpu-simple, and that seems to work well.

    Try it in SDK14.2.0 first, to make sure that everything is working before you port it to whichever SDK version you are using. Read README.md -> "How to use" for a description on how to test it.

    If I misunderstand what you are trying to do, please let me know, but these drivers should be working.

    Best regards,

    Edvin

Reply
  • Hello,

    Can you please check out this github repository:

    https://github.com/Martinsbl/nrf5-mpu-examples

    There are a few examples there that uses the sensor that you mentioned, the MPU6050. I have tested the nrf5-ble-mpu-simple, and that seems to work well.

    Try it in SDK14.2.0 first, to make sure that everything is working before you port it to whichever SDK version you are using. Read README.md -> "How to use" for a description on how to test it.

    If I misunderstand what you are trying to do, please let me know, but these drivers should be working.

    Best regards,

    Edvin

Children
No Data
Related