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.

  • Hi nRF5xFanBoy and thanks for your reply!

    I thought the question is more clear now :) 

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

    Yes, I do! So, if we are looking at the posted el. schematics already here then these are E1, E2, F3, F5, F7 , while on the right hand side are the available nrf52820 pins, see below:

    E1 => P0.14 

    E2 => P0.20

    F3 => "not sure what should be used here"

    F5 => P0.02

    F7 => P0.08

    Lets say I would like to assign the TWI, namely F5 = SDA and the F7 = SCL ... not really sure how to consider the in/out properties of the TWI.. with regard to the GPIO configuration...

    So, can you quickly shoot an example of how to configure the GPIOs for that? In addition, how would you test, with software, if my GPIOs are healthy either for input or output.

    Will have to look at the links provided.

    Best.

  • Hi MuRa,

    sorry to place the reply here, this site sometimes does not show the reply button under recent tickets. ????

    F5 => P0.02
    F7 => P0.08

    Lets say I would like to assign the TWI, namely F5 = SDA and the F7 = SCL ... not really sure how to consider the in/out properties of the TWI.. with regard to the GPIO configuration...

    then just change some code in my given example (see earlier posts)

    const uint32_t scl_pin = NRF_GPIO_PIN_MAP(0, 2); /*port-0 pin2 (= F5) */   
    const uint32_t sda_pin = NRF_GPIO_PIN_MAP(0, 8); /*port-0 pin8  (=F7) */

    By doing this the nrf52820 will route (internally) the pin F5/F7 not to the GPIO but to the TWImaster.
    so no worry about gpio input/output (they do not exist then.

    2nd question: about testing.
    I think about attaching a oscilloscope (or my favorite Saleae a logic analyzer) to the F5 and F7 and check the signals.

    Kind regards,
       nRF5xFanBoy

Related