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

Parents
  • Hi, 

    I recommend reading the TWIM chapter and the TWIS chapter in the product specification for nRF52832.

    The master device (TWIM) is in your case the nRF58832, while sensor and EEPROM are slaves. 

    If your nRF52832 will work as a slave (TWIS), then you need another microcontroller functioning as a master.

    You will find a suitable example to communicate with two devices in the TWI Transaction Manager Example which I linked to yesterday.

    Kind regards,
    Øyvind

  • Hi, Can you please tell me what is the difference of  TWI0 and TWI1

    #ifndef TWI0_ENABLED
    #define TWI0_ENABLED 1
    #endif
    // <q> TWI0_USE_EASY_DMA  - Use EasyDMA (if present)
     
    
    #ifndef TWI0_USE_EASY_DMA
    #define TWI0_USE_EASY_DMA 1
    #endif
    
    // </e>
    
    // <e> TWI1_ENABLED - Enable TWI1 instance
    //==========================================================
    #ifndef TWI1_ENABLED
    #define TWI1_ENABLED 0
    #endif
    // <q> TWI1_USE_EASY_DMA  - Use EasyDMA (if present)
     
    
    #ifndef TWI1_USE_EASY_DMA
    #define TWI1_USE_EASY_DMA 0
    #endif

    shall i enable both twi instance.

    what is

    TWI0_USE_EASY_DMA 1  - use case?

    #define TWI1_USE_EASY_DMA 0 - use case?

    if i enable both twi instance

    means

    the EASY_DMA of TWI1 also be '1' or '0'

  • 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:

Reply Children
No Data
Related