Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

LIS2DH12 driver issue in nRF SDK v15.0

Hi,

There are several new drivers under "nRF5_SDK_15.0.0_a53641a\components\drivers_ext\", but no example now.

I have setup the HTS221 driver and it works. I turn to LIS2DH12 driver, but it not work.

For send and receive more i2c data then HTS221, I change some Marco like this:

#define MAX_PENDING_TRANSACTIONS    33

#define LIS2DH12_MIN_QUEUE_SIZE       32

And read who_am_i successfully.

when try to read accelerate data, it stuck in somewhere, where I cannot traced.

Could you kindly share with me a example, which is using the new LIS2DH12 driver?

Parents
  • Hi ,

    I'm too trying to setup the LIS2DH12 driver to read out the WHO_AM_I register. I've adapted the twi_sensor example code according to my needs and your code snippets. Due to some previous issues when compiling I used the sdk_config.h from the twi_master_using_nrf_twi_mngr example.

    When I run the attached code the application starts, runs to the "Here." debug print, crashes and resets to continue in an endless cycle.

    Would you mind sharing a minimal example on how to read out the WHO_AM_I register using the drivers or point me in a general direction to keep searching?

    /* TWI instance ID. */
    #define TWI_INSTANCE_ID             0
    #define MAX_PENDING_TRANSACTIONS    33
    #define LIS2DH12_MIN_QUEUE_SIZE     32
    
    NRF_TWI_MNGR_DEF(m_nrf_twi_mngr, MAX_PENDING_TRANSACTIONS, TWI_INSTANCE_ID);
    NRF_TWI_SENSOR_DEF(m_nrf_twi_sensor, &m_nrf_twi_mngr, LIS2DH12_MIN_QUEUE_SIZE);
    LIS2DH12_INSTANCE_DEF(m_lis2dh12, &m_nrf_twi_sensor, LIS2DH12_BASE_ADDRESS_HIGH);
    
    static uint8_t m_sample = 0;
    
    void print_identity(ret_code_t r, void *p_register_data)
    {
        NRF_LOG_INFO("Identity: %d", *((uint8_t *)p_register_data));
    }
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("TWI sensor example started.");
        NRF_LOG_FLUSH();
    
        ret_code_t err = lis2dh12_init(&m_lis2dh12);
        NRF_LOG_INFO("Here.");
        NRF_LOG_FLUSH();
        APP_ERROR_CHECK(err);
        while (true)
        {
            nrf_delay_ms(500);
            err = lis2dh12_who_am_i_read(&m_lis2dh12, print_identity, &m_sample);
            APP_ERROR_CHECK(err);
            NRF_LOG_FLUSH();
        }
    }
    

  • Maybe you could check the err from :

    ret_code_t err = lis2dh12_init(&m_lis2dh12);

    What is it?

     

    BR,

    Edvin

  • Whoops! That fixed it. I changed that for some reason looking at your above post. Before it was failing because I wasn't initiating twi_sensor.

    Edit: Actually it worked because it programmed the DK instead of the external board which does't have the low frequency oscillator. Is it required for TWI?

    Edit 2: Changed it to RC in SDK config and it worked. I'll take that as a yes to my question.

  • Hi everyone,

    sorry for the delayed reply. I managed to get it working thanks to - I was oblivious to the fact that you have to init m_nrf_twi_mngr and m_nrf_twi_sensor to configure the pins ...

    the UART debug output went as follows

    <info> app: TWI sensor example started.
    <info> app: Here.
    <error> app: Fatal error
    <warning> app: System reset


    My suspicion is that due to the uninitialized m_nrf_twi_mngr / m_nrf_twi_sensor the driver didn't knew which pins belonged to the sensor / was getting an "uninitialized something" error at some point.

    It works fine now with the code provided below. Take note that I'm using the nRF52 DevKit and have hooked up the sensors SCL to P0.27 and SDA to P.026.

    /**
     * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
     * 
     * All rights reserved.
     * 
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     * 
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     * 
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     * 
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     * 
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     * 
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     * 
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * 
     */
    /** @file
     * @defgroup tw_sensor_example main.c
     * @{
     * @ingroup nrf_twi_example
     * @brief TWI Sensor Example main file.
     *
     * This file contains the source code for a sample application using TWI.
     *
     */
    
    #include <stdio.h>
    #include "boards.h"
    #include "app_util_platform.h"
    #include "app_error.h"
    #include "nrf_drv_twi.h"
    #include "nrf_delay.h"
    
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #include "lis2dh12.h"
    
    #include "nrf_twi_mngr.h"
    
    /* TWI instance ID. */
    #define TWI_INSTANCE_ID             0
    
    #define MAX_PENDING_TRANSACTIONS    33
    
    #define LIS2DH12_MIN_QUEUE_SIZE     32
    
    NRF_TWI_MNGR_DEF(m_nrf_twi_mngr, MAX_PENDING_TRANSACTIONS, TWI_INSTANCE_ID);
    
    NRF_TWI_SENSOR_DEF(m_nrf_twi_sensor, &m_nrf_twi_mngr, LIS2DH12_MIN_QUEUE_SIZE);
    
    LIS2DH12_INSTANCE_DEF(m_lis2dh12, &m_nrf_twi_sensor, LIS2DH12_BASE_ADDRESS_HIGH);
    
    static uint8_t m_sample = 0;
    
    void print_identity(ret_code_t r, void *p_register_data)
    {
        NRF_LOG_INFO("Identity: %d", *((uint8_t *)p_register_data));
    }
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        uint32_t err;
    
        nrf_drv_twi_config_t const config = {
           .scl                = 27,
           .sda                = 26,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_LOWEST,
           .clear_bus_init     = false
        };
    
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("TWI sensor example started.");
        NRF_LOG_FLUSH();
    
        err = nrf_twi_mngr_init(&m_nrf_twi_mngr, &config);
        APP_ERROR_CHECK(err);
    
        err = nrf_twi_sensor_init(&m_nrf_twi_sensor);
        APP_ERROR_CHECK(err);
    
        err = lis2dh12_init(&m_lis2dh12);
        APP_ERROR_CHECK(err);
    
        NRF_LOG_INFO("Here.");
        NRF_LOG_FLUSH();
        APP_ERROR_CHECK(err);
    
        while (true)
        {
            nrf_delay_ms(500);
            err = lis2dh12_who_am_i_read(&m_lis2dh12, print_identity, &m_sample);
            APP_ERROR_CHECK(err);
            NRF_LOG_FLUSH();
        }
    }
    
    /** @} */



    Thanks a lot!

  • Hi, 

    how do you know the sensor instance name (m_lis2dh12)? I try the same code and I have an error:

    macro names must be identifiers

    in lis2dh12.h

    Thanks!

  • how do you know the sensor instance name (m_lis2dh12)?

    because you define it:

    LIS2DH12_INSTANCE_DEF( m_lis2dh12, &m_nrf_twi_sensor, LIS2DH12_BASE_ADDRESS_HIGH );

    I have an error
    macro names must be identifiers

    Where, exactly, do you get that?

    Post the full message: copy it, and paste as for source code, but leave the 'Language' as 'Text' - ie, just steps 1 & 2:

  • It's ok, it works. But what is the expected result of who_am_i read and the function print_identity with this line:

    NRF_LOG_INFO("Identity: %d", *((uint8_t *)p_register_data)); 

Reply Children
Related