This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How can I set the trigger of the adxl362 to a specific value?

Hi, I am working with the adxl362 sensor on the Thingy91 and I want to set the trigger of the sensor to a specific value. 

In the datasheet (https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf), it says that the threshold should be adjustable. In the Zephyr Documentation (https://docs.zephyrproject.org/latest/reference/peripherals/sensor.html), I found that there is a SENSOR_TRIG_THRESHOLD and that it can be configurated with  SENSOR_ATTR_LOWER_THRESH and SENSOR_ATTR_UPPER_THRESH, but I have no idea how to use them in the code. Does someone could give me an example code line on how to set the trigger?

Thanks for your help!

  • I solved it by my own with the help of the timing diagram:

    I have a working code for the read area of the diagram and I need a code that works for the write area of the diagram. I need to expand the buffer and send 3 bytes instead of 2. The working code is:

    void spi_write_reg(void)
    {
      u8_t cmd =      0x0A;
      u8_t reg_addr = 0x20; // register, that you want to write
      u8_t value = 0x46; // value, that you want to set
      void *data = &value;
      int length = 1;
    	u8_t access[3] = { cmd, reg_addr, value };
    
      gpio_pin_write(cs_gpio, cd_pin, 0);
    
    	const struct spi_buf buf[2] = {
    		{
    			.buf = access,
    			.len = 3
    		},
    		{
    			.buf = data,
    			.len = length
    		}
    	};
    	struct spi_buf_set tx = {
    		.buffers = buf,
    	};
    
    
    	const struct spi_buf_set rx = {
    		.buffers = buf,
    		.count = 2
    	};
    
    	tx.count = 1;
    
    	int spi_result = spi_transceive(spi_dev, &spi_cfg, &tx, &rx);
    
     // printk("SPI result: %d\n",spi_result);
      printk("Value: 0x%02X\n", value);
    
      gpio_pin_write(cs_gpio, cd_pin, 1);
    
    }

Related