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,

    I have looked into your code, and I can see that you are trying to use driver specific function (adxl362_set_range).

    However, as we can see the function is not defined and the build system cannot locate it.

    You can have two solutions:

    1) You get the driver header and source files and include in your project explicitly. You might need to change / update header files or the function prototypes.

    2) You can use Zepher sensor Api to access the driver functions.

    As in the second case, 

          you already have included the sensor.h

          you have already defined your sensor node in the overlay file

          you already have the obtained the DTS node using zephyr devicetree api

          also, you are already using sensor api, for example sensor_trigger_set and sensor_sample_fetch, and sensor_channel_get etc.

    As you can see you are already using sensor api to access the functionality of the underlying driver. 

    Similarly, you can use "sensor_attr_set()" function to access those driver functions that you have mentioned.

    Hope it helps,

    Regards

Reply
  • Hello Saeed,

    I have looked into your code, and I can see that you are trying to use driver specific function (adxl362_set_range).

    However, as we can see the function is not defined and the build system cannot locate it.

    You can have two solutions:

    1) You get the driver header and source files and include in your project explicitly. You might need to change / update header files or the function prototypes.

    2) You can use Zepher sensor Api to access the driver functions.

    As in the second case, 

          you already have included the sensor.h

          you have already defined your sensor node in the overlay file

          you already have the obtained the DTS node using zephyr devicetree api

          also, you are already using sensor api, for example sensor_trigger_set and sensor_sample_fetch, and sensor_channel_get etc.

    As you can see you are already using sensor api to access the functionality of the underlying driver. 

    Similarly, you can use "sensor_attr_set()" function to access those driver functions that you have mentioned.

    Hope it helps,

    Regards

Children
  • Hi Naeem

    As you mentioned I have already used sensor api  to fetch and get sensor data. So I used

     sensor_attr_set(dev,SENSOR_CHAN_ACCEL_XYZ,SENSOR_ATTR_FULL_SCALE,8);

    command in my code to change the full sacle default of the sensor from 2g to 8g.The program

    was compiled and built with no errors but nothing changes and the limiting value of accelerations

    are still 2g. there is only a warning issued:

    passing argument 4 of 'sensor_attr_set' makes pointer from integer without a cast [-Wint-conversion]

    expected 'const struct sensor_value *' but argument is of type 'int'

    Would you please guide me how to use  sensor_attr_set() function to make effects.

  • 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