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

Migrating from nrf5_SDK to nrf connect sdk

Hello,

I am migrating code from nrf5_SDK_17.0.2 to nrf connect sdk v1.6.1. The board i am using is nrf52dk(nrf52832) connected with adafruit LSM6DSO.

Everything works fine on nrf5_SDK which based on modified example twi_sensor. But when I run lsm6dso example from zephyr\samples\sensor\lsm6dso, it says

Cannot set sampling frequency for accelerometer. -134

I have tried manually write register to i2c address like what I does on nrf5_SDK but hard fault occurs.

    //uint8_t buf[2] = {0x10, 0x10};
    //int ret = i2c_write(dev, buf, 1, 0x10);
    int ret = i2c_reg_write_byte(dev, 0x6a, 0x10, 0x10);
    if (ret < 0){
        printf("cannot i2c_burst_write");
    }else {
        printf("custom i2c_burst_write");
    }

Any help would be appreciated.

prj.conf

CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_LSM6DSO=y
CONFIG_LSM6DSO_TRIGGER_NONE=y
CONFIG_CBPRINTF_FP_SUPPORT=y

modified part of nrf52dk_nrf52832.dts

arduino_i2c: &i2c0 {
	compatible = "nordic,nrf-twi";
	status = "okay";
	sda-pin = <26>;
	scl-pin = <27>;

	lsm6dso@6a {
		compatible = "st,lsm6dso";
		label = "LSM6DSO";
		reg = <0x6a>;
	};
};

Parents
  • Hello,

    I refer to LSM6DSO: IMU Sensor Monitor sample of Zephyr.

    If you add the sensor via the devicetree (which I by the way recommend you do via an overlay file and not directly in the .dts), you have to use the Sensor API. One fundamental step is to bind the device probably, as shown here.

    I hope this will help you :-)

    Regards,

    Markus

  • Hello Markus,

    Thank you so much for responding. I can confirm that the device is properly binded because the device pointer does not return NULL. But I have few questions as follow.

    1. LSM6DSO contains a set of registers to control sensor behavior.

    What I does in nRF5_SDK looks like the following,

        uint8_t reg[2] = {0x10, 0b00010000};
        nrf_drv_twi_xfer_desc_t xfer = NRF_DRV_TWI_XFER_DESC_TX(0x6a, reg, sizeof(reg));
        err_code = nrf_drv_twi_xfer(&m_twi, &xfer, 0);
        APP_ERROR_CHECK(err_code);
        while (m_xfer_done == false);

    How can I achieve the same effect using the high level Sensor API or low level I2C API?

    2. What is wrong with the following code? It is hard to debug as it crashes without any error code. I think the code should be corrected by following the readme.

        // @brief Write internal register of an I2C device.
        //
        // @param dev       Pointer to the device structure for an I2C controller driver configured in master mode. 
        // @param dev_addr  Address of the I2C device for writing.
        // @param reg_addr  Address of the internal register being written.
        // @param value     Value to be written to internal register.
        
        int ret = i2c_reg_write_byte(dev, 0x6a, 0x10, 0x10);
        if (ret < 0){
            printf("cannot i2c_burst_write");
        }else {
            printf("custom i2c_burst_write");
        }

    2021-09-20T03:14:23.225Z DEBUG modem << *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    2021-09-20T03:14:24.666Z DEBUG modem << Testing LSM6DSO sensor in polling mode.
    2021-09-20T03:14:25.584Z DEBUG modem << [00:00:00.320,770] [0m<inf> LSM6DSO: chip id 0x6c[0m
    2021-09-20T03:14:25.609Z DEBUG modem << [00:00:02.690,612] [1;31m<err> os: ***** USAGE FAULT *****[0m
    2021-09-20T03:14:25.641Z DEBUG modem << [00:00:02.690,612] [1;31m<err> os:   Illegal use of the EPSR[0m
    2021-09-20T03:14:25.673Z DEBUG modem << [00:00:02.690,612] [1;31m<err> os: r0/a1:  0x200000d8  r1/a2:  0x200010fc  r2/a3:  0x00000001[0m
    2021-09-20T03:14:25.716Z DEBUG modem << [00:00:02.690,643] [1;31m<err> os: r3/a4:  0x0000006a r12/ip:  0x0000000a r14/lr:  0x00001621[0m
    2021-09-20T03:14:25.758Z DEBUG modem << [00:00:02.690,643] [1;31m<err> os:  xpsr:  0x00000000[0m
    2021-09-20T03:14:25.786Z DEBUG modem << [00:00:02.690,643] [1;31m<err> os: Faulting instruction address (r15/pc): 0x00000000[0m
    2021-09-20T03:14:25.822Z DEBUG modem << [00:00:02.690,643] [1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0[0m
    2021-09-20T03:14:25.859Z DEBUG modem << [00:00:02.690,643] [1;31m<err> os: Current thread: 0x20000250 (unknown)[0m
    2021-09-20T03:14:25.890Z DEBUG modem << [00:00:02.997,009] [1;31m<err> fatal_error: Resetting system[0m

    Also, Sensor API looks good that abstract sensor sampling. I would try this after sensor reporting the correct sensor readings.

    -- Updated the hard fault debug message

  • Hello, today I have tested other manufacturer sensor (Infineon DPS310) and similar problem appears.

    On one hand, nrf52832 read register correctly.

    	int res = i2c_reg_read_byte(data->i2c_master, config->i2c_addr,
    				 IFX_DPS310_REG_ADDR_PRODUCT_ID, &product_id);

    On the other hand, it does not generate waveform when read and write register.

    	res = i2c_write_read(data->i2c_master, config->i2c_addr,
    			     &REG_ADDR_CALIB_COEFF_0, 1, &raw_coef, 18);

    1. The above are calling the same command i2c_write_read. I think something is wrong with I2C and nordic twim library because it is impossible that both example code from two different manufacturers do not work.

    2. I have found similar problem on devzone: https://devzone.nordicsemi.com/f/nordic-q-a/74704/dps310-zephyr-example-not-working-with-the-nrf9160-sdk

    Is he able to tackle this problem?

Reply
  • Hello, today I have tested other manufacturer sensor (Infineon DPS310) and similar problem appears.

    On one hand, nrf52832 read register correctly.

    	int res = i2c_reg_read_byte(data->i2c_master, config->i2c_addr,
    				 IFX_DPS310_REG_ADDR_PRODUCT_ID, &product_id);

    On the other hand, it does not generate waveform when read and write register.

    	res = i2c_write_read(data->i2c_master, config->i2c_addr,
    			     &REG_ADDR_CALIB_COEFF_0, 1, &raw_coef, 18);

    1. The above are calling the same command i2c_write_read. I think something is wrong with I2C and nordic twim library because it is impossible that both example code from two different manufacturers do not work.

    2. I have found similar problem on devzone: https://devzone.nordicsemi.com/f/nordic-q-a/74704/dps310-zephyr-example-not-working-with-the-nrf9160-sdk

    Is he able to tackle this problem?

Children
No Data
Related