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

How to set I2C slave address?

Hi,

I'm considering using NRF52832/52840 as BLE central while configuring its I2C as slave.

Should I initialize I2C with TWIS instance? How do I suppose to set the slave address?

I've check the "twi_master_with_twis_slave" sample of SDK16. But I'm bit of confused since the sample is bonding TWIS with FLASH.

Perhaps I just need to implement this part to initialize TWIS?

const nrf_drv_twis_config_t config =
    {
        .addr               = {m_config.slave_addr, 0},
        .scl                = m_config.scl_s,
        .scl_pull           = NRF_GPIO_PIN_PULLUP,
        .sda                = m_config.sda_s,
        .sda_pull           = NRF_GPIO_PIN_PULLUP,
        .interrupt_priority = APP_IRQ_PRIORITY_HIGH
    };

    /* Init TWIS */
    do
    {
        ret = nrf_drv_twis_init(&m_twis, &config, twis_event_handler);
        if (NRF_SUCCESS != ret)
        {
            break;
        }

        nrf_drv_twis_enable(&m_twis);
    }while (0);
    return ret;

Address here is defined as:

#define EEPROM_SIM_ADDR                   0x50    //!< Simulated EEPROM TWI slave address.

If I were use several NRF52s as slaves, how do I suppose to set each address? Does the 7 bits fully customizable?

Thanks

Parents
  • Hi Jared,

    Sorry for late reply, I've been working on TWI and TWIS communication.

    Here are few more points I wish to confirm:

    • When "nrf_drv_twi_tx" processed,  slave "TWIS_EVT_WRITE_REQ" will be called.
    • When slave address is set to 0x10, I don't have to implement the address to fit read/write application since nrf_drv_twi_tx/nrf_drv_twi_rx will fill the last bit automatically
    • ACK bit will be sent automatically by slave

    Thanks

Reply
  • Hi Jared,

    Sorry for late reply, I've been working on TWI and TWIS communication.

    Here are few more points I wish to confirm:

    • When "nrf_drv_twi_tx" processed,  slave "TWIS_EVT_WRITE_REQ" will be called.
    • When slave address is set to 0x10, I don't have to implement the address to fit read/write application since nrf_drv_twi_tx/nrf_drv_twi_rx will fill the last bit automatically
    • ACK bit will be sent automatically by slave

    Thanks

Children
Related