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,

     

    Should I initialize I2C with TWIS instance?

     Yes

     

    How do I suppose to set the slave address

     The slave address should be sent to the master after the master sends a read request. The read request event TWIS_EVT_READ_REQ is then generated. The TWIM with eeprom shows how this should be done in the eeprom_simulator.c file. 

     

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

     Yes almost. There are some reserved addresses but other than that, you can pretty much set it to what you like. 

     

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

     That's enough to initialize it but you have to implement a callback handler that reacts to requests from the Master etc.

    regards

    Jared 

Reply
  • Hi,

     

    Should I initialize I2C with TWIS instance?

     Yes

     

    How do I suppose to set the slave address

     The slave address should be sent to the master after the master sends a read request. The read request event TWIS_EVT_READ_REQ is then generated. The TWIM with eeprom shows how this should be done in the eeprom_simulator.c file. 

     

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

     Yes almost. There are some reserved addresses but other than that, you can pretty much set it to what you like. 

     

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

     That's enough to initialize it but you have to implement a callback handler that reacts to requests from the Master etc.

    regards

    Jared 

Children
No Data
Related