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

I2C in nrf51 SDK

I want to interface ADXl345 with nrf51 SDK. suppoose my device address is 0x53 and register address is 0x2D and i want to write value 8. now nordic i2c has function nrf_drv_twi_tx with attributes nrf_drv_twi_t const *const p_instance, uint8_t address, uint8_t const * p_data, uint32_t length, bool xfer_pending

now here my address is 0x53, length is 6. now can you tell me where to write register address? where to write data??

Parents Reply Children
  • I am running the code of twi sensor, where I have added the adxl part,

    here is the code of main

    int main(void)
    {


    uint16_t a;
    // nrf_delay_ms(1000);
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    ret_code_t ret_code;

    ret_code = twi_master_init();

    ADXL375_I2C_init(&m_twi_master);

    int16_t x_val;
    int16_t y_val;
    int16_t z_val;
    a=1;
    NRF_LOG_INFO("A=%d",a);

    ADXL375_I2C_data_rate_set(0x0A);
    ADXL375_I2C_offsets_set(0,0,0);


    APP_ERROR_CHECK(ret_code);

    a=2;

    while (1)
    {
    NRF_LOG_INFO("A=%d",a);
    a=3;
    //NRF_LOG_INFO("A=%d",a);


    ADXL375_I2C_acc_data_read(&x_val,&y_val,&z_val);
    NRF_LOG_INFO("A=%d",a);

    NRF_LOG_INFO("x=%d, y=%d, z=%d",x_val,y_val,z_val);
    //SEGGER_RTT_printf(0,"ACC DATA: X: %d Y: %d Z: %d \n", x_val ,y_val, z_val);
    nrf_delay_ms(500);

    // Do nothing.
    }
    }

    it will print A=1

    then comes a fatal error, here is the screen shot

     

    Help me in this, Thanks

  • Why are you using a PCA10056(NRF52840 DK) Segger Embedded Studio project, when you state that you want to interface the ADXl345 with a nRF52 DK?

    Also note that TWI driver used to make the ADXl345 was made for a 3 year old SDK and may not be compatible with the SDK version you are using? WHich version is it? Is it SDK v15.0.0 or newer?

  • I am currently using nRF_SDK_15.2.0, also i am usinng PCA10056 because its for nRF52840-DK like PCA10059 is for nRF52 Dongle. I have nRF52840 development kit so i have chosen PCA10056, Isn't it more or less similar with nRF52 DK, is there any main difference between nRF52 DK or nRF52840 DK? I just want to interface adxl-345 with my nRF52840 development kit using your library, but I am unable to get any values when I put these lines in the code.

    ADXL375_I2C_data_rate_set(0x0A);
    ADXL375_I2C_offsets_set(0,0,0);

    also I have changed the SDA, SCL pins accordingly in TWI like

    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,
    .clear_bus_init = false
    };

    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;
    }

    where twi_handler is as

    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;
    }
    }

    also I have defined SDA SCL pins according to the development kit, in the header file as


    #define TWI_SCL_M 27 //!< Master SCL pin

    #define TWI_SDA_M 26 //!< Master SDA pin
    #define MASTER_TWI_INST 0 //!< MASTERTWI interface

    /** I2C BUS ADRESSES*/
    #define ADXL375_ADDR 0x53


    /** REGISTER ADDRESSES */
    #define DEVICE_ID 0x00
    #define OFSX 0x1E
    #define OFSY 0x1F
    #define OFSZ 0x20

    #define BW_RATE 0x2C
    #define POWER_CTL 0x2D
    #define DATAX0 0x32
    #define DATAY0 0x34
    #define DATAZ0 0x36

    But still I  am not getting  cann't get any value. Can you help me out in this. Thanks

  • OK, are you able to capture a logic trace of the SDA and SCL lines going to the ADXL345 ?

Related