TWI apis

hi team,

i am using nrf52840 controller and sdk 16.0 i want to know difference between twi and twim and twis driver apis in infocenter.which one i have to use once i connect external i2c based eeprom module through GPIOs.and i have another doubt for master and slave i have configure separately and i have to enable interrupts separately.

static ret_code_t twi_master_init(void)
{
    
    const nrf_drv_twi_config_t config =
    {
       .scl                = TWI_SCL_M,
       .sda                = TWI_SDA_M,
       .frequency          = NRF_DRV_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    nrf_drv_twi_init(&m_twi_master, &config, NULL, NULL);
ret_code_t eeprom_simulator_init(void)
{
    ret_code_t ret;

    m_config.slave_addr                = EEPROM_SIM_ADDR;
    m_config.scl_s                     = EEPROM_SIM_SCL_S;
    m_config.sda_s                     = EEPROM_SIM_SDA_S;
    m_config.flash_start_addr          = EEPROM_SIM_FLASH_ADDRESS;

    /* Initialize RAM with contents of flash */
    for (uint32_t n=0; n<EEPROM_SIM_SIZE; ++n)
    {
        m_memory[n] = *(uint8_t *)(m_config.flash_start_addr + n);
    }
    m_addr = 0;

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

  • Hi,

    • TWI is legacy TWI Master peripheral without support for EasyDMA. When using this, the CPU needs to update the data pointer for each byte being transmitted/received.
    • TWIM is the more modern TWI Master peripheral with EasyDMA support, allowing you to transfer larger blocks of data directly from/to RAM, without any CPU intervention.
    • TWIS is TWI slave peripheral, used when you have an external master that should be able to read/write data from/to the nRF. This also supports EasyDMA.

    For our use-case, I would recommend using the TWIM API.

    Best regards,
    Jørgen

Related