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

  • Hi Kenneth,

             Thanks for your reply. I solved that issue. Now my question is I have 3 slaves connected to NRF52840 on the same I2C lines SCL pin as P1.09 and SDA pin as P0.11. I am able to connect to slave 1. Now for adding slave 2 and slave 3 do I need to add something extra or I can read all 3 slaves from the same instance?? 

    Warm Regards,

    Snehal.

  • Hi,

    Good to hear you have solved it. There should be nothing in specific needed to handle 3 slaves, you only need to update the address for each slave, and also I suggest wait for the previous transaction to complete before starting the next.

    Kenneth

  • Hi Kenneth,

                         I had one question. I have a I2c slave device SAMD20, I am able to initiate a connection with samd20. Now I want to send sample data "0xaa" through I2c. SAMD20 has no registers. It is directly configured as a slave device with slave id 0x54. How can i send data through i2c?? 

    I am trying to use this code:- 

    bool samd20_register_write(uint8_t register_address, uint8_t value)
    {
    ret_code_t err_code;
    uint8_t tx_buf[SAMD20_ADDRESS_LEN+1];

    //Write the register address and data into transmit buffer
    tx_buf[0] = register_address;
    tx_buf[1] = value;

    //Set the flag to false to show the transmission is not yet completed
    m_xfer_done = false;

    //Transmit the data over TWI Bus
    err_code = nrf_drv_twi_tx(&m_twi, SAMD20_ADDRESS, tx_buf, SAMD20_ADDRESS_LEN+1, false);

    //Wait until the transmission of the data is finished
    while (m_xfer_done == false)
    {
    }

    // if there is no error then return true else return false
    if (NRF_SUCCESS != err_code)
    {
    return false;
    }

    return true;
    }

    But I am confused what should I pass as register address?? I have only slave address configured in the slave which is 0x54. SAMD20_ADDRESS =0x54. How do I send data ?? 

    samd20_register_write(register_address, 0xaa); 

    Please help me on this. 

  • I believe you are mixing a bit the Device (slave) address with the Register address(es). There are two typical sequences in 2-wire (I2C) transactions, to illustrate the write and read operations you can look at the below Figures:

    I suggest that you add a logic analyzer to the 2-wire (I2C) pins to see the actual data.

    Kenneth

  • Hi Kenneth,

        I am not having logic analyzer. I am not confusing between 2 addresses. I understand that slave address is used as an identifier by the master and register address is internal addresses of the slave device. But in my case, I dont have any registers in my slave device. So how to send data?? What to put in place of register address?

    Thanks & Regards,

    Snehal.

Related