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

ADXL345 with nrf52DK, error

Im trying to interface ADXL345 with nrf52DK via I2C. Im using the reference drivers in below link

https://devzone.nordicsemi.com/f/nordic-q-a/40822/adxl345-and-nrf52832

i edited the main function to include twi_handler, 

/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 */

/** @file
* @brief Example template project.
* @defgroup nrf_templates_example Example Template
*
*/

#include <stdbool.h>
#include "SEGGER_RTT.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "boards.h"
#include "ADXL375_I2C.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_gpio.h"

/**
 * @brief TWI master instance
 *
 * Instance of TWI master driver 
 *
 */
static const nrf_drv_twi_t m_twi_master = NRF_DRV_TWI_INSTANCE(MASTER_TWI_INST);

static   int16_t x_val;
static  int16_t y_val;
static    int16_t z_val;
static volatile bool m_xfer_done;

void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{   
   switch (p_event->type)
{
case NRF_DRV_TWI_EVT_DONE:
if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
{
ADXL375_I2C_acc_data_read(&x_val, &y_val, &z_val);
}
m_xfer_done = true;
break;
default:
break;
}
}

/**
 * @brief Initialize the master TWI
 *
 * Function used to initialize master TWI interface that would communicate with simulated EEPROM.
 *
 * @return NRF_SUCCESS or the reason of failure
 */
static ret_code_t twi_master_init(void)
{
    ret_code_t ret;
    const nrf_drv_twi_config_t config =
    {
       .scl                = TWI_SCL_M,
       .sda                = TWI_SDA_M,
       .frequency          = NRF_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH
    };

    do
    {
        ret = nrf_drv_twi_init(&m_twi_master, &config,twi_handler, NULL);
        if(NRF_SUCCESS != ret)
        {
            break;
        }
        nrf_drv_twi_enable(&m_twi_master);
    }while(0);
    return ret;
}


/**
 * @brief Function for application main entry.
 */
int main(void)
{
    ret_code_t ret_code;
    
    ret_code = twi_master_init();
    
    ret_code = ADXL375_I2C_init(&m_twi_master);
    
    ADXL375_I2C_data_rate_set(0x0A);
    ADXL375_I2C_offsets_set(0,0,0);
    

    
    
    APP_ERROR_CHECK(ret_code);
    while (true)
    {
        m_xfer_done = false;
        bsp_board_led_invert(BSP_BOARD_LED_0);
        ADXL375_I2C_acc_data_read(&x_val,&y_val,&z_val);
        NRF_LOG_INFO(0,"ACC DATA:  X: %d  Y: %d  Z: %d  \n", x_val ,y_val, z_val);
         NRF_LOG_FLUSH();
         nrf_delay_ms(100);
         while (!m_xfer_done)
        {
            __WFE();
        }

        NRF_LOG_FLUSH();
        bsp_board_led_invert(BSP_BOARD_LED_0);
        nrf_delay_ms(1000);
        
        // Do nothing.
    }
}
/** @} */
,

the control when trying to enable the TWI, enters the twi_enable function, after completing the function last line( at last breakpoint) , goes into NRF_BREAKPOINT COND.

Can you kindly help me resolve this?

wrt sdk settings,

what all should be enabled? what not. such as NRFX_TWIM and NRFX_TWI and TWI

Parents
  • Hi,

     

    what all should be enabled? what not. such as NRFX_TWIM and NRFX_TWI and TWI

     Depends on what peripherals that you are going to use. The TWIM and TWI are two different peripherals. The former uses EasyDMA, the latter doesn't.  Where exactly is the program asserting? The debug window you've shared shows that it has stopped at a breakpoint? Are you getting any error from the logger module?

    regards

    Jared

Reply
  • Hi,

     

    what all should be enabled? what not. such as NRFX_TWIM and NRFX_TWI and TWI

     Depends on what peripherals that you are going to use. The TWIM and TWI are two different peripherals. The former uses EasyDMA, the latter doesn't.  Where exactly is the program asserting? The debug window you've shared shows that it has stopped at a breakpoint? Are you getting any error from the logger module?

    regards

    Jared

Children
Related