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

[nRF51 to nRF52 Migration] TWI issues

Hi,

I am currently migrating my controller from nRF51 to nRF52832 . I am facing an issue where in when I try to do an TWI communication with MPU9250 on nRF52 the code gets stuck in the TWI commands. 

I am using SDK12.3. 

The code that I am using to access the Sensor through nRF52 is same as the one used for accessing the sensor through nRF51. Can you let me know if I need to make any change to the TWI access instruction to allow for communication between nRF52 and MPU9250.

Thanks

Parents Reply Children
  • Hi Kenneth,

    I used used the twi example in SDKv12.3 and modified the code to read the who am I register in MPU9250 .

    I am getting an "NRF_ERROR_BUSY" error when I try to read the register. 

    So the code progress all the way till line 44 and gets stuck there.

    Here is the code snippet.

    /**
     * @brief TWI initialization.
     */
    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = SCL_PIN_NUMBER,
           .sda                = SDA_PIN_NUMBER,
           .frequency          = NRF_TWI_FREQ_400K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }
    
    /**
     * @brief Function for reading data from MPU9250 sensor.
     */
    static void read_whi_data()
    {
        m_xfer_done = false;
        ret_code_t err_code;
        uint8_t data[2] ={0,0};
    
       
        err_code= nrf_drv_twi_tx(&m_twi,0x68,&who_am_i_reg,1,1);
        if (err_code!=NRF_SUCCESS)
        {
            CYAN_ON();
            while(1){}
        }
    
        BLUE_ON();
        
        err_code = nrf_drv_twi_rx(&m_twi,0x68,data,1);
        if (err_code == NRF_ERROR_BUSY)
        {
            WHITE_ON();
            while(1){}
        }
    
        if (data[0] == 0x71)
        {
            PURPLE_ON();
        }
        else
        {
            GREEN_ON();
        }
    
    }
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        LED_init();
        
        twi_init();
        
        RED_ON();
        nrf_delay_ms(1000);
        read_whi_data();
        while (true)
        {
            nrf_delay_ms(500);
    
            do
            {
                __WFE();
            }while (m_xfer_done == false);
        }
    }

  • I have 10K resistors pulling up my SCL and SDA lines to VDD. But when I check the voltage (without enabling TWI) my SDA is not pulled up to VDD.

    I have connected SDA to pin 9 which is the NFC1 input. Does this cause any issues ? My SCL is connected to Pin 8 and that is pulled up to VDD.

  • Ok, I believe the issue was that I was using the NCF 1 pin with disabling the NFC. Once I added the preprocessor directive CONFIG_NFCT_PINS_AS_GPIOS.

    I was able to get the Sensor working.

Related