ADXL362 registers writing

Hi 

I am using ADXL362 moving sensor in my nrf5340 custom board. In a previous ticket I could achieve to read its registers by modifying the overlay file 

according to my hardware design. Now  I want to know how can I write to its registers by SPI commands. For example I want to increase its g measurement

range from 1g to 8g. For your information I am using nRF connect for Desktop software for writing and programing my custom board.

Thank you in advance for your support.

Best Regards

Saeed Mahvis

Parents
  • Hello Saeed,

    Thank you for contacting DevZone at NordicSemi.

    Regarding accessing your sensor registers, It depends how you are already doing/accessing your sensor.

    I could not see your case related to SPI based sensor. 

    Nonetheless, as an example, you could use adxl362_set_reg() to write data to your device register by providing register address.

    This function is very specific for your sensor.

    Hope it helps.

    Regards,
    Naeem

  • Hi Naeem

    As you mentioned above there are a lot of functions available to work with ADXL632. Which ever of these functions

    I used the compiler issues errors like this:

     undefined reference to `adxl362_set_range'

    ld returned 1 exit status

    I have used a thread for using ADXL362 in my program. Below is my code: 

    void adxl362_thread(void)
    {

    char res[50];
    double ax,ay,az,ambient_temp;
    struct sensor_value accel[3],temp[1];


    const struct device *dev = device_get_binding(DT_LABEL(DT_INST(0, adi_adxl362)));

    if (IS_ENABLED(CONFIG_ADXL362_TRIGGER)) {
    struct sensor_trigger trig = { .chan = SENSOR_CHAN_ACCEL_XYZ };

    trig.type = SENSOR_TRIG_THRESHOLD;
    if (sensor_trigger_set(dev, &trig, trigger_handler)) {
    printf("Trigger set error\n");
    return;
    }

    trig.type = SENSOR_TRIG_DATA_READY;
    if (sensor_trigger_set(dev, &trig, trigger_handler)) {
    printf("Trigger set error\n");
    }
    }

    ///////// system reset command __NVIC_SystemReset();


    adxl362_set_range(dev,8);

    while(1) {
    /*
    if (IS_ENABLED(CONFIG_ADXL362_TRIGGER)) {
    k_sem_take(&sem, K_FOREVER);
    } else {
    k_msleep(1000);
    if (sensor_sample_fetch(dev) < 0) {
    printf("Sample fetch error\n");
    return;
    }
    }*/
    sensor_sample_fetch(dev);
    //k_msleep(100);
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &accel[0]);
    ax = sensor_value_to_double(&accel[0]);

    if( ax > 12.5 ){

    strcpy(res,"Ax =");
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    ftoa(ax,res,4);
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    strcpy(res,"\r\n");
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    }
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &accel[1]);
    ay = sensor_value_to_double(&accel[1]);
    if ( ay > 12.5 ) {
    strcpy(res,"Ay =");
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    ftoa(ay,res,4);
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    strcpy(res,"\r\n");
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    }

    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &accel[2]);
    az = sensor_value_to_double(&accel[2]);
    if( az > 12.5 ) {
    strcpy(res,"Az =");
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    ftoa(az,res,4);
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    strcpy(res,"\r\n");
    uart_tx(uart,res,strlen(res), SYS_FOREVER_MS);
    k_msleep(2);
    }



    }

    }
    K_THREAD_DEFINE(adxl362_id, 1024, adxl362_thread, NULL, NULL, NULL, PRIORITY, 0, 0);

    The above mentioned error I said is related to this line:

    adxl362_set_range(dev,8)

    How can I use these functions.

    B.R.

    Saeed

  • Hi Saeed,

    Were you facing any such issue when you were reading the registers from sensor?

    Can you please send your minimal project just enough to reproduce the error you are facing.

    Regards,

    Naeem

  • Hi Naeem

    This is my prj.conf file:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #

    # CONFIG_PM_DEVICE=y

    CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
    CONFIG_BT_SMP=y
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y

    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    # CONFIG_NRFX_UARTE0=y
    CONFIG_SERIAL=y

    CONFIG_GPIO=y

    # Make sure printk is not printing to the UART console
    CONFIG_CONSOLE=n
    CONFIG_UART_CONSOLE=n

    CONFIG_HEAP_MEM_POOL_SIZE=2048
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="KMS"
    CONFIG_BT_DEVICE_APPEARANCE=833
    CONFIG_BT_MAX_CONN=1
    CONFIG_BT_MAX_PAIRED=1
    CONFIG_BT_NUS_UART_BUFFER_SIZE=512
    # Enable the NUS service
    CONFIG_BT_NUS=y

    # Enable DK LED and Buttons library
    CONFIG_DK_LIBRARY=y

    # This example requires more workqueue stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

    # Config logger
    CONFIG_LOG=n
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_ASSERT=y

    CONFIG_SPI=y
    CONFIG_SENSOR=y
    CONFIG_ADXL362=y
    CONFIG_ADXL362_TRIGGER_GLOBAL_THREAD=y
    CONFIG_ADXL362_INTERRUPT_MODE=1
    CONFIG_ADXL362_ABS_REF_MODE=1

    and also this my overlay file:

    &uart0 {
    compatible = "nordic,nrf-uarte";
    reg = < 0x8000 0x1000 >;
    interrupts = < 0x8 0x1 >;
    status = "okay";
    label = "UART_0";
    current-speed = < 115200 >;
    tx-pin = < 0x14 >;
    rx-pin = < 0x05 >;
    rts-pin = <35>;
    cts-pin = <36>;
    };


    &spi3 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    sck-pin = <24>;
    mosi-pin = <16>;
    miso-pin = <14>;
    cs-gpios = <&gpio0 19 GPIO_ACTIVE_LOW>;

    adxl362: spi-dev-adxl362@0 {
    compatible = "adi,adxl362";
    label = "ADXL362";
    spi-max-frequency = <8000000>;
    reg = <0>;
    int1-gpios = <&gpio0 9 0>;

    };

    };


    &spi2 {

    status = "disabled";

    };

    &led0 {
    gpios = < &gpio0 0x1d 0x1 >;
    label = "Green LED 0";
    };

    And as I said previously when I write this line in my code:

    adxl362_set_range(dev,8);

    compiler issues error message.

    B.R.

    Saeed

  • Dear Saeed,

    Which SDK version you are using?

    What problem you are getting with that function? What is the error? 

    Please send the minimal project in the zip file, as I am not able to build based on your code and produce the error related to the said function.

    Please mention what error you are getting and how you are building the project.

    In your proj.conf you have "CONFIG_BT_NUS_UART_BUFFER_SIZE=512"

    but there is no such KCONFIG option available with nCS. 

    Regards

Reply
  • Dear Saeed,

    Which SDK version you are using?

    What problem you are getting with that function? What is the error? 

    Please send the minimal project in the zip file, as I am not able to build based on your code and produce the error related to the said function.

    Please mention what error you are getting and how you are building the project.

    In your proj.conf you have "CONFIG_BT_NUS_UART_BUFFER_SIZE=512"

    but there is no such KCONFIG option available with nCS. 

    Regards

Children
No Data
Related