Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Accessing the nrf52820 pins

Hello all

I am porting the code from the nRF52DK to the nrf52820, and so far so good, however, I am having a question, when configuring the TWI, will this get me the right PINS, for instance, according to the module manufacturer I should be accessing the P0.02 for SDA, while P0.08 for the SCL , this is my code:

void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
       .scl                = NRF_GPIO_PIN_MAP(0, 8), // ARDUINO_SCL_PIN,   //Add you SCL Pin Here
       .sda                = NRF_GPIO_PIN_MAP(0, 2), // ARDUINO_SDA_PIN,   //Add you SDA Pin Here
       .frequency          = NRF_DRV_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&m_twi, &twi_config, twi_handler, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&m_twi);
}

This part works on the nrf52dk, for example where I am directly using the P0.27 and P0.26, however, the numbers 26 and 27 are simply used, as 26 and 27... 

hence my question, if I am accessing the pins correctly?

best.

Parents
  • Hello all, 

    I think I have to change the question here, to aim at what I am looking for :) for example, I am looking at how to configure the GPIOs on the module that is based on the nrf52820 !

    For example, on particular GPIOs I want to have the TWI Slight smile 

    On other GPIOs I want to have the interrupt, while on others I would like to blink the led, and so on...

    So, how to configure the GPIOs on the nrf52820 with the nrf52sdk is the question , right?

    Looking forward to any ideas, suggestions how to tackle this...

    Best.

  • Hi MuRa,


    Great an easy question :)   Yes the nordic Micrcontroller is very flexible in routing pins to a specific source (like TWI or SPI or GPIO etc.)

    Do you known which port/pins (based upon your electrical drawing) do you like to assign to the TWI ?

    more details information on the TWI 
    https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fhardware_driver_twi.html

    For example :
    I will pick the pins 4 & 5 because they are not used and are free (as you can see in you your electrical drawing) 
    So I in my code below I do assign port/pin P0.04 + P0.05 as scl & sda for the twi - master.

    nrf_drv_twi_t twi_drv;
    
    const uint32_t scl_pin = NRF_GPIO_PIN_MAP(0, 4); /*port-0 , pin4* /
    const uint32_t sda_pin = NRF_GPIO_PIN_MAP(0, 5); /*port-0 , pin5 */
    
    const nrf_drv_twi_config_t config =
    {
    .scl = scl_pin,
    .sda = sda_pin,
    .frequency = (nrf_drv_twi_frequency_t)frequency, // give a value
    .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
    .clear_bus_init = false,
    .hold_bus_uninit = false
    };
    
    if ( NRF_SUCCESS != nrf_drv_twi_init( &twi_drv, &config, NULL, NULL ) )
    {
      // error
    }
    else
    {
      nrf_drv_twi_enable( &twi_drv_ );
    }
    
    
     


    Hope my answer does help you, have a nice (coding) day.

    Kind regards,
            nRF5xFanBoy

Reply
  • Hi MuRa,


    Great an easy question :)   Yes the nordic Micrcontroller is very flexible in routing pins to a specific source (like TWI or SPI or GPIO etc.)

    Do you known which port/pins (based upon your electrical drawing) do you like to assign to the TWI ?

    more details information on the TWI 
    https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fhardware_driver_twi.html

    For example :
    I will pick the pins 4 & 5 because they are not used and are free (as you can see in you your electrical drawing) 
    So I in my code below I do assign port/pin P0.04 + P0.05 as scl & sda for the twi - master.

    nrf_drv_twi_t twi_drv;
    
    const uint32_t scl_pin = NRF_GPIO_PIN_MAP(0, 4); /*port-0 , pin4* /
    const uint32_t sda_pin = NRF_GPIO_PIN_MAP(0, 5); /*port-0 , pin5 */
    
    const nrf_drv_twi_config_t config =
    {
    .scl = scl_pin,
    .sda = sda_pin,
    .frequency = (nrf_drv_twi_frequency_t)frequency, // give a value
    .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
    .clear_bus_init = false,
    .hold_bus_uninit = false
    };
    
    if ( NRF_SUCCESS != nrf_drv_twi_init( &twi_drv, &config, NULL, NULL ) )
    {
      // error
    }
    else
    {
      nrf_drv_twi_enable( &twi_drv_ );
    }
    
    
     


    Hope my answer does help you, have a nice (coding) day.

    Kind regards,
            nRF5xFanBoy

Children
No Data
Related