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

TWI init conflicting with BLE initialisation calls

Hello. I've used the design template that initialises everything for Bluetooth communication. These are the initialisation calls made in main():

// Initialize
leds_init();
timers_init();
gpiote_init();
buttons_init();
ble_stack_init();
scheduler_init();
gap_params_init();
advertising_init();
services_init();
conn_params_init();
sec_params_init();
    
// Start execution
timers_start();
advertising_start();

I then add a TWI init call from the "TWI master" example, but that hangs the chip (nRF51822) during the execution of the TWI initialisation routine. If I comment out some of the other initialisation calls, like so

// Initialize
leds_init();
timers_init();
gpiote_init();
buttons_init();
//ble_stack_init();
scheduler_init();
//gap_params_init();
//advertising_init();
services_init();
//conn_params_init();
sec_params_init();
    
// Start execution
timers_start();
//advertising_start();

twi_init() does not hang, and I'm able to talk to my peripheral over the TWI bus. Before I go investigate more closely why this happens, I was wondering if anyone else has experienced this before, and what might be a possible solution. I'm using the pin assignment from the example code if that's relevant:


#define TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER (24U)
#define TWI_MASTER_CONFIG_DATA_PIN_NUMBER (25U)
Parents
  • Most likely, its not the pin numbering that is making the example not work. Have you tried debugging and see what happens?

    Most likely, you are getting an assert somewhere. If you comment in the assert handler, you are able to read out which line/file/error code you are getting:

    
    void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
    {
        nrf_gpio_pin_set(ASSERT_LED_PIN_NO);
    
        // This call can be used for debug purposes during development of an application.
        // @note CAUTION: Activating this code will write the stack to flash on an error.
        //                This function should NOT be used in a final product.
        //                It is intended STRICTLY for development/debugging purposes.
        //                The flash write will happen EVEN if the radio is active, thus interrupting
        //                any communication.
        //                Use with care. Un-comment the line below to use.
        **ble_debug_assert_handler(error_code, line_num, p_file_name);**
    
        // On assert, the system can only recover on reset
        **//** NVIC_SystemReset();
    }    
    }
    
  • This file is something we at tech support have modified to make it softdevice compatible. I have pushed this to the R&D team to have them integrate a "softdevice" friendly library for all peripherals that are using restricted features (like PPI/random number generator etc).

    All peripherals that are blocked/restricted or open are shown in the S110 specification, so when you get an error like this, you'll have to make sure that you are doing something "legal" in terms of which peripheral you are accessing.

    The TWI is open and can be accessed directly, but in this case it's a couple of PPI channels that are being assigned inside the TWI library, which is very hidden and thats not fortunate.

Reply
  • This file is something we at tech support have modified to make it softdevice compatible. I have pushed this to the R&D team to have them integrate a "softdevice" friendly library for all peripherals that are using restricted features (like PPI/random number generator etc).

    All peripherals that are blocked/restricted or open are shown in the S110 specification, so when you get an error like this, you'll have to make sure that you are doing something "legal" in terms of which peripheral you are accessing.

    The TWI is open and can be accessed directly, but in this case it's a couple of PPI channels that are being assigned inside the TWI library, which is very hidden and thats not fortunate.

Children
No Data
Related