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

AT24C512 + BMI160 + NRF52

Hi,

I am using nRF52832 soc to develop my project. with nRF5_SDK_15.3 . SES file

I need to connect both BMI160 accelerometer sensor and AT24C512 EEPROM ic in TWI.

how to use TWI with this. guide me to use both at a time.

BMI160 separately i can read the data.

but i can't read while connect to AT24C512

  • if i give same sda and scl pin to eeprom and bmi. it gives fatal error

    If you're going to use two separate TWI Masters, then they need to be separate - they cannot share the same pins!

    Again, this is clearly stated in the Product Specification:

    "Only one peripheral can be assigned to drive a particular GPIO pin at a time. Failing to do so may result in unpredictable behavior."

  • As the device has EasyDMA present, you want to enable this:

    TWI0_USE_EASY_DMA 1

  • I'm sorry, I am not able to see what is wrong from your code. Can you please debug the code and give me the error message you receive with the fatal error?

    Kind regards,
    Øyvind

  • The error code

    #define ARDUINO_SCL_PIN             27    // SCL signal pin
    #define ARDUINO_SDA_PIN             26    // SDA signal pin
    #define ARDUINO1_I2C_SCL_PIN 30
    #define ARDUINO1_I2C_SDA_PIN 31
    
    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_mma_EEP_config  = {
           .scl                = ARDUINO_SCL_PIN,
           .sda                = ARDUINO_SDA_PIN,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           
        };
        const nrf_drv_twi_config_t twi_config = {
           .scl                = ARDUINO_SCL_PIN,
           .sda                = ARDUINO_SDA_PIN,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
          // .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi_mma_EEP, &twi_mma_EEP_config, NULL, NULL); //twi_handler
         APP_ERROR_CHECK(err_code);
        if (NRF_SUCCESS == err_code)
    	{
    		nrf_drv_twi_enable(&m_twi_mma_EEP);
    		NRF_LOG_INFO("TWI0 init success...");	
    	}
        err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
    
           APP_ERROR_CHECK(err_code);
        if (NRF_SUCCESS == err_code)
    	{
    		nrf_drv_twi_enable(&m_twi);
    		NRF_LOG_INFO("TWI init success...");	
    	}
    		
       err_codecpy=err_code;
    		nrf_delay_ms(5);
    }

    code changed

    #define ARDUINO_SCL_PIN             27    // SCL signal pin
    #define ARDUINO_SDA_PIN             26    // SDA signal pin
    #define ARDUINO1_I2C_SCL_PIN 30
    #define ARDUINO1_I2C_SDA_PIN 31
    
    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_mma_EEP_config  = {
           .scl                = ARDUINO1_I2C_SCL_PIN,
           .sda                = ARDUINO1_I2C_SDA_PIN,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           
        };
        const nrf_drv_twi_config_t twi_config = {
           .scl                = ARDUINO_SCL_PIN,
           .sda                = ARDUINO_SDA_PIN,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
          // .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi_mma_EEP, &twi_mma_EEP_config, NULL, NULL); //twi_handler
         APP_ERROR_CHECK(err_code);
        if (NRF_SUCCESS == err_code)
    	{
    		nrf_drv_twi_enable(&m_twi_mma_EEP);
    		NRF_LOG_INFO("TWI0 init success...");	
    	}
        err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
    
           APP_ERROR_CHECK(err_code);
        if (NRF_SUCCESS == err_code)
    	{
    		nrf_drv_twi_enable(&m_twi);
    		NRF_LOG_INFO("TWI init success...");	
    	}
    		
       err_codecpy=err_code;
    		nrf_delay_ms(5);
    }

    when i changed the different scl sda pins separate then it works

    but my case i need to connect both eeprom and sensor in a same pins

  • when i changed the different scl sda pins separate then it works

    That has already been explained to you: you cannot have two different TWI Masters sharing the same pins!

    i need to connect both eeprom and sensor in a same pins

    Then you must use just one TWI Master - as  showed you in the diagram he posted earlier:

Related