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

i2c_nrfx_twim: Error 0x0BAE0002 when setting I2C interrupt

Hello,

I get an error message when running this function:

int ret = i2c_reg_write_byte(data->dev, cfg->i2c_addr,
            LSM6DSOX_INT1_CTRL, test);

I know 0x0BAE0002 error means NRFX_ERROR_DRV_TWI_ERR_DNACK but hard to tell what is the cause of this error.

If I run the sensor in polling mode, everything works fine which can exclude error because of wiring.

Any help on this will be helpful.

Here is the error message.

2021-09-23T09:50:21.478Z DEBUG modem << *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
2021-09-23T09:50:23.399Z DEBUG modem << Testing LSM6DSO sensor in trigger mode.
2021-09-23T09:50:23.452Z DEBUG modem << [00:00:04.368,957] [1;31m<err> os: ***** Spurious interrupt (IRQ  6) *****[0m
2021-09-23T09:50:23.454Z DEBUG modem << [00:00:04.368,957] [1;31m<err> os: r0/a1:  0x20001400  r1/a2:  0x00004965  r2/a3:  0x0000a2bf[0m
2021-09-23T09:50:23.496Z DEBUG modem << [00:00:04.368,988] [1;31m<err> os: r3/a4:  0x000049b9 r12/ip:  0x000049b9 r14/lr:  0x000049b9[0m
2021-09-23T09:50:23.540Z DEBUG modem << [00:00:04.368,988] [1;31m<err> os:  xpsr:  0x00000000[0m
2021-09-23T09:50:23.556Z DEBUG modem << [00:00:04.368,988] [1;31m<err> os: Faulting instruction address (r15/pc): 0x000049b9[0m
2021-09-23T09:50:23.594Z DEBUG modem << [00:00:04.369,018] [1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0[0m
2021-09-23T09:50:23.640Z DEBUG modem << [00:00:04.369,018] [1;31m<err> os: Current thread: 0x200003b8 (unknown)[0m
2021-09-23T09:50:23.690Z DEBUG modem << [00:00:04.626,678] [1;31m<err> fatal_error: Resetting system[0m
2021-09-23T09:51:36.834Z DEBUG modem << *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
2021-09-23T09:51:37.617Z DEBUG modem << No device "LSM6DSOX" found.
2021-09-23T09:51:37.839Z DEBUG modem << [00:00:01.063,354] [1;31m<err> i2c_nrfx_twim: Error 0x0BAE0002 occurred for message 0[0m

overlay

arduino_i2c: &i2c0 {
	lsm6dsox@6a {
		compatible = "st,lsm6dsox";
		label = "LSM6DSOX";
		reg = <0x6a>;
		irq-gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>,<&gpio0 12 GPIO_ACTIVE_HIGH>;
		int-pin = <1>;
	};
};

The function cause this error

static int lsm6dsox_enable_xl_int(const struct device *dev, int enable)
{
	const struct lsm6dsox_config *cfg = dev->config;
	struct lsm6dsox_data *data = dev->data;

	if (enable) {
		/* dummy read: re-trigger interrupt */
        int16_t buf[3];
        if (i2c_burst_read(data->dev, cfg->i2c_addr,
                   LSM6DSOX_REG_DATA_START_NO_TEMP, (uint8_t *)buf, 6) < 0) {
            LOG_ERR("Failed to read data sample.");
            return -EIO;
        }
	}

	/* set interrupt */
	if (cfg->int_pin == 1) {
		lsm6dsox_int1_ctrl_t int1_ctrl;

		if (i2c_reg_read_byte(data->dev, cfg->i2c_addr, 
			LSM6DSOX_INT1_CTRL, (uint8_t*)&int1_ctrl) < 0) {
			return EIO;
        }
		int1_ctrl.int1_drdy_xl = enable;
        uint8_t test = 0x01;
        // this line trigger Spurious interrupt (IRQ  6)
		int ret = i2c_reg_write_byte(data->dev, cfg->i2c_addr, 
			LSM6DSOX_INT1_CTRL, test);
        if (ret != 0){
          printf("cannot write");
        }
        return ret;
	} 
}

int lsm6dsox_trigger_set(const struct device *dev,
			  const struct sensor_trigger *trig,
			  sensor_trigger_handler_t handler)
{
	struct lsm6dsox_data *lsm6dsox = dev->data;

	if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) {
		lsm6dsox->handler_drdy_acc = handler;
		if (handler) {
			return lsm6dsox_enable_xl_int(dev, LSM6DSO_EN_BIT);
		} else {
			return lsm6dsox_enable_xl_int(dev, 0);
		}
	} else if (trig->chan == SENSOR_CHAN_GYRO_XYZ) {
		lsm6dsox->handler_drdy_gyr = handler;
		if (handler) {
			return lsm6dsox_enable_g_int(dev, 1);
		} else {
			return lsm6dsox_enable_g_int(dev, 0);
		}
	}
	
	return -ENOTSUP;
}

Parents
  • Same problem with me with the lsm6dso. When write i received nack error from slave but sensor received the information. I can't verify with logic analyzer for the moment.

    Function with suprious error code.

    lsm6dso_write_reg(ctx, LSM6DSO_INT1_CTRL,
    (uint8_t *)&int1_ctrl, 1);
Reply
  • Same problem with me with the lsm6dso. When write i received nack error from slave but sensor received the information. I can't verify with logic analyzer for the moment.

    Function with suprious error code.

    lsm6dso_write_reg(ctx, LSM6DSO_INT1_CTRL,
    (uint8_t *)&int1_ctrl, 1);
Children
No Data
Related