NRF52840 I2C ADDRESS.

Hello Everyone,

                           I am working on NRF52840 development kit. I am trying to run I2c master. My main goal is to send some data to slave via I2C lines. I am using the example code "TWI scanner" from the sdk examples. I have attached the slave microcontroller (ATSAMD20) and I am running i2c slave code on it. The Slave address is 0x54. I have set it as 0x54 in the slave code. Now when I try to scan the devices from NRF52840, the device is found at 0x28 address. Why is it so?? 

  • Looking at the api for nrf_drv_twi_tx() there is nothing preventing you from just set the first byte of p_data to your value instead of register_adress.

    /**
     * @brief Function for sending data to a TWI slave.
     *
     * The transmission will be stopped when an error occurs. If a transfer is ongoing,
     * the function returns the error code @ref NRF_ERROR_BUSY.
     *
     * @param[in] p_instance Pointer to the driver instance structure.
     * @param[in] address    Address of a specific slave device (only 7 LSB).
     * @param[in] p_data     Pointer to a transmit buffer.
     * @param[in] length     Number of bytes to send.
     * @param[in] no_stop    If set, the stop condition is not generated on the bus
     *                       after the transfer has completed successfully (allowing
     *                       for a repeated start in the next transfer).
     *
     * @retval NRF_SUCCESS                  If the procedure was successful.
     * @retval NRF_ERROR_BUSY               If the driver is not ready for a new transfer.
     * @retval NRF_ERROR_INTERNAL           If an error was detected by hardware.
     * @retval NRF_ERROR_INVALID_ADDR       If the EasyDMA is used and memory adress in not in RAM.
     * @retval NRF_ERROR_DRV_TWI_ERR_ANACK  If NACK received after sending the address in polling mode.
     * @retval NRF_ERROR_DRV_TWI_ERR_DNACK  If NACK received after sending a data byte in polling mode.
     */
    __STATIC_INLINE
    ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
                              uint8_t               address,
                              uint8_t const *       p_data,
                              uint8_t               length,
                              bool                  no_stop);

    Best regards,
    Kenneth

  • Hi Kenneth,

                  I tried doing that also but no luck. The strange part is when I try to initialize it using the function below, I get a SUCCESS message, but when I try to send data to samd20 nothing is being received on samd20.

    SAMD20_ADDR = 0X54;

    bool samd20_i2c_init(void)
    {
    ret_code_t err_code;
    // uint8_t address = 0x54;
    uint8_t sample_data = 0x00;

    err_code = nrf_drv_twi_rx(&m_twi,SAMD20_ADDR,&sample_data,sizeof(sample_data));
    if(err_code == NRF_SUCCESS)
    {
    NRF_LOG_INFO("SUCCESS 999");
    //flag_led = 1;
    return true;
    }
    else
    {
    NRF_LOG_INFO("FAILED");
    return false;
    }

    }

    I don't understand why I am not receiving anything on SAMD20.I am really stuck here badly and not understanding how to proceed.

    Thanks & Regards,

    Snehal.

  • Please get a logic analyzer so you can observe the data. 

    Kenneth

Related