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

nRF52840 pinout confusion

I might be dense here, but please bear with me and clarify something.   I am looking at the SPI bus as drawn on the nRF52840. According to the schematics (PCA10056 - nRF52840 MCU) ,the spi bus is assigned as follows:  

So, SS, MOSI, MISO and SCK should correspond to P1.12, P1.13, P1.14, and P1.15, respectively.  However, looking at the example code (specifically for spi_pca10056) the assignments show the following in the sdk_config.h file:  #define SPI_SCK_PIN 26 (which corresponds to <26=> 26 (P0.26)), #define SPI_MISO_PIN 30 (which corresponds to <30=> 30 (P0.30)), #define SPI_MOSI_PIN 29 (which corresponds to <29=> 29 (P0.29)) and #define SPI_SS_PIN 31 (which corresponds to <31=> 31 (P0.31) ).  I really don't understand how these pin assignments occur in the configurator(CMSIS Wizard).  In this code example, SPI0_Enabled was selected.  Does this automatically identify the set of pins to enabled?  Where is this mapping done? And in this case the mapping looks incorrect?   What am I missing?

Thanks for clearing up my confusion in advance.

Jim

  • Hello,

    If you search for e.g. SPI_SCK_PIN in your project, you should see that it is used a couple of places. It is defined in sdk_config.h, and used in main.c in the unmodified SDK\examples\peripheral\spi example:

        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config.ss_pin   = SPI_SS_PIN;
        spi_config.miso_pin = SPI_MISO_PIN;
        spi_config.mosi_pin = SPI_MOSI_PIN;
        spi_config.sck_pin  = SPI_SCK_PIN;
        APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

    So there aren't really any predefined SPI pins. It is just what happened to be set as a default in this example's sdk_config.h file. You can set it to whatever pins you like. The intended way to modify this is to do it in the sdk_config.h file.

    NB: Please take a look at the back side of your SDK before you assign any other pins for your SPI. Please note that some of the pins are used by buttons, LEDs and the NFC on the DK.

    In this code example, SPI0_Enabled was selected.  Does this automatically identify the set of pins to enabled?

     No. SPI0 refers to the SPI instance, and you are using the first SPI instance. If you would want to add another SPI, you could use SPI1. 

    So if the question really is how to select pin P1.xx, then this is mapped so that the P1.xx pins continues where P0.yy finished. I.e. P1.00 = 32, P1.01 = 33, P1.xx = 32+xx. There is a macro for this that you can also use (and you can use this in sdk_config.h as well), and you can see that it is already used in pca10056.h.

    #define MY_CUSTOM_PIN = NRF_GPIO_PIN_MAP(1, 14)

    The macro NRF_GPIO_PIN_MAP() is defined in nrf_gpio.h, and it just adds 32 if the first input parameter is 1.

    Best regards,

    Edvin

Related