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

  • Hi Saeed,

    Sorry for the delay.

    Good to know that you made progress.

    How to use sensor_attr_set() fucntion:

    Reading from the Zephyr sensor API documentation, we see that this function requires a pointer to sensor_value as last parameter:

    In your case, you are directly providing an integer value of 8.

    Now, lets see how this sensor_value works:

    This struct has two integers: val1 and val2, we you need to set both of these values to achieve your desired value. This is how it works:

    So you need to define a pointer variable of type struct sensor_value, and set both of its integers (val1 and val2) to your specific values (as per your calculations), and then provide this pointer as last parameter to the function.

    something like this:

    struct sensor_value myvals;
    myvals.val1 = someval1;
    myvals.val2 = someval2; //as per your calculations
    
    //later in the code
    sensor_attr_set(dev, channel, attribute, &myvals);

    Regards,

    Naeem

Related