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 MuRa,

    Sorry for the late feedback (i had a long ad hoc meeting ;-)

    mmh this electronic drawing is not very clear in the pin naming (it's a good puzzle)
    You just need to hunt all the chip's proper datahseets and collect all the information.


    1st question about the twi_config / pins


    Looking at the PAN1781 product datahseet
    nl.mouser.com/.../IntegrationGuideRFModulePAN1781Series052421.pdf
    On page 10 you will see the pins identifiers C4 & C5 (not handy labels for software people ;-)

    if you search the labels in the WM PAN1781 Product Specification.pdf  
    https://mediap.industry.panasonic.eu/assets/custom-upload/Devices/Wireless%20Connectivity/Bluetooth%20Low%20Energy%20Modules/PAN1781/WM%20PAN1781%20Product%20Specification.pdf

    On page 11  you will find:
    C4 = SWDIO , Digital BI,  Serial Wire Data I/O
    C5 = SWDCLK, Digital IN,  Serial Wire Data Clock


    I only do not see any official TWI (i2c) pins coming out of the microcontroller / PAN1781 module.
    I only see the SWDCLK & SWDIO.
    As you can see in the datasheet of the Nordic nrf52820 https://infocenter.nordicsemi.com/pdf/nRF52820_OPS_v0.7.pdf.
    It tells you that it is impossble to use theese pins as a normal TWI pins?
    More information on the control access port (for the debug access port) is on page 43

    unclear what you want with the TWI on the pan1781 route to the swd pins?


    2nd question  "I have tried to toggle the P0.14 ....   now I would like to do the same with the P0.20?"
    The the answer is simple 
    nrf_gpio_pin_write(12, 1); // to make the gpio  level high (assume positive signal level.)
    nrf_gpio_pin_write(12, 0); // to make the gpio  level low 


    3rd question: "reach the pin F3"
    The names are copied from the FT232R chip datasheet (https://nl.mouser.com/datasheet/2/163/DS_FT232R-11534.pdf see page 7)
    The USB D- wire is called at the FT232RQ -> pin no. 15 USB Data Signal Plus

    The USB D+ wire is called at the FT232RQ -> pin no. 16 USB Data Signal Minus 

    The 'M' perhaps indicate the PAN1781 is a bus-Master (or MCU) on this interface?
    I am not sure, my advise, just try to follow the interfacing as is described in the FT232R chip datasheet.

    Thanks for the nice puzzle

    Hope my answers do help you, have a nice day.

    Kind regards,
            nRF5xFanBoy

  • Hi and thank you for your input!

    I will try to answer your questions and elaborate what I had in mind.

    On page 10 you will see the pins identifiers C4 & C5 (not handy labels for software people ;-)

    Not sure what are you aiming here? btw SWDCLK, SWDIO , works ok, I can easily program the module. 

    I only do not see any official TWI (i2c) pins coming out of the microcontroller / PAN1781 module.

    I do not see it either, this is why I am looking at how to use the available GPIOs ... I think the GPIOs can be used for TWI...

    It tells you that it is impossble to use theese pins as a normal TWI pins?

    I am not trying to use the SWD..pins for the TWI...

    unclear what you want with the TWI on the pan1781 route to the swd pins?

    See above...

    2nd question  "I have tried to toggle the P0.14 ....   now I would like to do the same with the P0.20?"
    The the answer is simple 
    nrf_gpio_pin_write(12, 1); // to make the gpio  level high (assume positive signal level.)
    nrf_gpio_pin_write(12, 0); // to make the gpio  level low 

    Thank you for that, it makes sense! Slight smile

    The names are copied from the FT232R chip datasheet

    Thanks for that , will have a look...

    Thanks and the same!

    Best.

  • 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

Related