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