I2C error when transferring large data

Hello,

I am working with a TOF sensor, and in the init I need to upload some firmware through an I2C connection. It functions as intended when it is a smaller amount of data but once it gets to the larger stuff (32 kB) I get this error:

"Error on I2C line occurred for message 0" from i2c_nrfx_twim.c

Could it be the I2C timeout? If so how do I change it?

I am using sdk 1.9.1, here is the function that throws the error in the second i2c_write() which sends the data:

uint8_t WrMulti(
	VL53L5CX_Platform *p_platform,
	uint16_t RegisterAddress,
	uint8_t *p_values,
	uint32_t size)
{
	uint8_t status = 255;
	uint8_t *reg;
	reg = &RegisterAddress;
	RegisterAddress = ((RegisterAddress << 8) & 0xff00) | ((RegisterAddress >> 8) & 0x00ff);

	status = i2c_write(p_platform->i2c_dev, reg, 2U, p_platform->address);
	if (status)
	{
		printf("WrMulti: Failed to write reg: %d\n", status);
	}
	status = i2c_write(p_platform->i2c_dev, p_values, size, p_platform->address);
	if (status)
	{
		printf("WrMulti: Failed to write bytes: %d\n", status);
	}

	return status;
}

Thanks,

Jacob

Parents
  • Hi,

    "Error on I2C line occurred for message 0" from i2c_nrfx_twim.c

    Have you received any code number for this error?

    Best regards,
    Dejan

  • ret = k_sem_take(&dev_data->completion_sync,
    				 I2C_TRANSFER_TIMEOUT_MSEC);
    		if (ret != 0) {
    			/* Whatever the frequency, completion_sync should have
    			 * been given by the event handler.
    			 *
    			 * If it hasn't, it's probably due to an hardware issue
    			 * on the I2C line, for example a short between SDA and
    			 * GND.
    			 * This is issue has also been when trying to use the
    			 * I2C bus during MCU internal flash erase.
    			 *
    			 * In many situation, a retry is sufficient.
    			 * However, some time the I2C device get stuck and need
    			 * help to recover.
    			 * Therefore we always call nrfx_twim_bus_recover() to
    			 * make sure everything has been done to restore the
    			 * bus from this error.
    			 */
    			printk("Error on I2C line occurred for message %d", i);
    			nrfx_twim_disable(&dev_config->twim);
    			nrfx_twim_bus_recover(dev_config->config.scl,
    					      dev_config->config.sda);
    			ret = -EIO;
    			break;
    		}

    Here is the if statement it enters, so it would return EIO but other than that no error code.

Reply
  • ret = k_sem_take(&dev_data->completion_sync,
    				 I2C_TRANSFER_TIMEOUT_MSEC);
    		if (ret != 0) {
    			/* Whatever the frequency, completion_sync should have
    			 * been given by the event handler.
    			 *
    			 * If it hasn't, it's probably due to an hardware issue
    			 * on the I2C line, for example a short between SDA and
    			 * GND.
    			 * This is issue has also been when trying to use the
    			 * I2C bus during MCU internal flash erase.
    			 *
    			 * In many situation, a retry is sufficient.
    			 * However, some time the I2C device get stuck and need
    			 * help to recover.
    			 * Therefore we always call nrfx_twim_bus_recover() to
    			 * make sure everything has been done to restore the
    			 * bus from this error.
    			 */
    			printk("Error on I2C line occurred for message %d", i);
    			nrfx_twim_disable(&dev_config->twim);
    			nrfx_twim_bus_recover(dev_config->config.scl,
    					      dev_config->config.sda);
    			ret = -EIO;
    			break;
    		}

    Here is the if statement it enters, so it would return EIO but other than that no error code.

Children
Related