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

Assigning a functional block to a GPIO

I'm confused about how to assign a functional block's I/O (TWI in my case) to a particular pin on the device. Is there a worked and documented example? Is there a relevant application note?

  • Sorry, I can't post the code right now on the forum.

    No, I'm not debugging -- where should I start? Any other advice would be appreciated. (I'm still stuck with not having the TWI pins wiggle.)

  • I've narrowed it down to the chip getting stuck when I call this function (it's unmodified from the example code):

    bool twi_master_init(void)
    {
        /* To secure correct signal levels on the pins used by the TWI
           master when the system is in OFF mode, and when the TWI master is 
           disabled, these pins must be configured in the GPIO peripheral.
        */
        NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = 
            (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
          | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos)
          | (GPIO_PIN_CNF_PULL_Pullup    << GPIO_PIN_CNF_PULL_Pos)
          | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos)
          | (GPIO_PIN_CNF_DIR_Input      << GPIO_PIN_CNF_DIR_Pos);    
    
        NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = 
            (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
          | (GPIO_PIN_CNF_DRIVE_S0D1     << GPIO_PIN_CNF_DRIVE_Pos)
          | (GPIO_PIN_CNF_PULL_Pullup    << GPIO_PIN_CNF_PULL_Pos)
          | (GPIO_PIN_CNF_INPUT_Connect  << GPIO_PIN_CNF_INPUT_Pos)
          | (GPIO_PIN_CNF_DIR_Input      << GPIO_PIN_CNF_DIR_Pos);    
    
        NRF_TWI1->EVENTS_RXDREADY = 0;
        NRF_TWI1->EVENTS_TXDSENT = 0;
        NRF_TWI1->PSELSCL = TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER;
        NRF_TWI1->PSELSDA = TWI_MASTER_CONFIG_DATA_PIN_NUMBER;
        NRF_TWI1->FREQUENCY = TWI_FREQUENCY_FREQUENCY_K100 << TWI_FREQUENCY_FREQUENCY_Pos;
        NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TWI1->EVENTS_BB;
        NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_SUSPEND;
        NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Msk;
        NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
    
        return twi_master_clear_bus();
    }
    

    What I see is the pins going high, as they should, but nothing more. What am I missing?

  • Hi again. Since I've used the template design as, well, my template, I had all the following init calls intact:

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

    That caused the twi_init() call to hang. However, if I comment out some of these 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();
    

    I see the clock running on the TWI SCK pin! Any hints on why this happens on how to resolve these potential conflicts? Thanks!

  • This sounds like you're not using the softdevice functions for manipulating the PPI. Please see this answer: https://devzone.nordicsemi.com/index.php/twi-on-nrf51822#reply-239

Related