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

SPI clock pin configuration for nRF52840.

Hi,

I am using nRF52840 on custom board. I am trying to configure SPI pins, but I am not getting anything on the clock pin. I can see the chip select pin going low and high which is good. But there is no clock on the pin. Following is the code snippet from my project.

#define MEM_CS                           NRF_GPIO_PIN_MAP(0,4)
#define MEM_SI                           NRF_GPIO_PIN_MAP(0,7)
#define MEM_SO                           NRF_GPIO_PIN_MAP(1,8)
#define MEM_SCK                          NRF_GPIO_PIN_MAP(0,13)

void memInit(void)
{
	    //GPIO configuration
        nrf_gpio_cfg_output(MEM_CS);
        nrf_gpio_cfg_output(MEM_SI);
        nrf_gpio_cfg_output(MEM_SCK);
        nrf_gpio_cfg_input(MEM_SO, GPIO_PIN_CNF_PULL_Pulldown);

                
        //SPI configuration
        nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
        spi_config.ss_pin    = MEM_CS;
        spi_config.miso_pin  = MEM_SO;
        spi_config.mosi_pin  = MEM_SI;
        spi_config.sck_pin   = MEM_SCK;
        spi_config.bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST;
        spi_config.frequency = NRF_SPI_FREQ_250K;
        spi_config.mode      = NRF_SPI_MODE_2;
        
        nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);

}

uint32_t memId()
{
        __disable_irq();
        
        nrf_gpio_pin_clear(MEM_CS);         //Pin goes low now

        err  = nrf_drv_spi_transfer(&spi, p_tx_buffer, sizeof(tx_buffer), NULL, 0);  
        nrf_delay_ms(100);
        
        nrf_gpio_pin_set(MEM_CS);           //Pin goes high now

	    __enable_irq();
        return err;
}

For my custom board configuration I have set Preprocessor definitions to BOARD_CUSTOM. But for simplicity, I have defined the pins in the source code file. I am thinking to test it first and then I can define the pins for SPI in custom_board.h. On the custom board I have checked for the pins they are not connected to any other peripheral. 

For development, I am using SES with nRF SDK15.0.0 and Softdevice S140. 

Any insight would be appreciated.

Thanks!

Parents
  • Hi Einar,

    So you should at least remove the call to __disable_irq().

    I tried removing the line __disable_irq(). But it didn't help. I am still not able to see the clock on the pin. I tried the code with the board supplied by Fanstel. I have attached the document from them which has the schematic for the dev kit I am using. I will really appreciate if you can have a look on the document and let me know if there is anything I am doing wrong with the pin selection for the purpose.

    M2_LN60E40F+Product+Specifications.pdf

    The LN60E40F is a module based on nRF9160 and nRF52840. For the schematic you can go to the page no. 25 of this document. The schematic is not having good resolution and that is frustrating for me as well. 

    Thank you for your efforts.

    Regards,

    Shivek

  • Hi Einar, 

    I already have tried that example. The screenshots I have attached are from the same example. So, that's why I asked if you can provide me the example which is not included in the SDK examples.

    Looking forward for your response to other questions as well.

    Regards,

    Shivek

  • Hi Shivek,

    I already have tried that example. The screenshots I have attached are from the same example. So, that's why I asked if you can provide me the example which is not included in the SDK examples.

    I see. I am not able to make any simpler example than that one, as it is minimal, so I think we need to look more at what you do instead, then. Perhaps you can show a complete project that reproduce this so that we see exactly what you do, as well as schematics for your custom board.

    So, if we want to use simple SPI peripheral (not using EasyDMA) with SPI0 instance, we need to set SPI0_ENABLEDSPI_ENABLED to 1 and we need to disable SPIM peripheral by setting NRFX_SPIM0_ENABLED, NRFX_SPIM_ENABLED to 0.

    Firstly, I found in the spi_master_using_nrf_spi_mngr that NRFX_SPIM_ENABLED is set to 1. May I ask why is that so?

    Unfortunately the driver configuration is a bit complex for legacy reasons. Generally, as you use the nrf_drv driver API (legacy API), the configuration macros starting with NRFX_ are irrelevant. What happens is that the macros starting with SPI* take precedence. and when it comes to using SPI or SPIM peripheral, that is decided by the value of SPI0_USE_EASY_DMA for instance 0, SPI1_USE_EASY_DMA for instance 1, etc.

    (Note that the API is the same in both cases, and you typically want to use the SPIM peripheral as it uses DMA. The driver handles all the differences for you, but that is much more sensible in a real application as the CPU can do other work while the SPIM peripheral handles the transaction.)

    Secondly, when I debug the same example on nrf52840, I can see the registers for both SPIM0 and SPI0 being configured with the same pins. Which can be a problem as described in the nrf52840 Product specifications. The document clearly says that only one peripheral can be associated to a particular pin at one point of time. 

    I see explained this good. All peripherals with the same register base address share the same physical components, and cannot be used at the same time. It does not make sense to look at the register of the other with the same address etc.

    I will appreciate if you can provide full settings for sdk_config.h or anything else, to use SPI0/SPIM0 with and without EasyDMA as I am not able to find any documentation on that. 

    Just refer to the mentioned example and change the value of SPI0_USE_EASY_DMA. that is the only required change.

Reply
  • Hi Shivek,

    I already have tried that example. The screenshots I have attached are from the same example. So, that's why I asked if you can provide me the example which is not included in the SDK examples.

    I see. I am not able to make any simpler example than that one, as it is minimal, so I think we need to look more at what you do instead, then. Perhaps you can show a complete project that reproduce this so that we see exactly what you do, as well as schematics for your custom board.

    So, if we want to use simple SPI peripheral (not using EasyDMA) with SPI0 instance, we need to set SPI0_ENABLEDSPI_ENABLED to 1 and we need to disable SPIM peripheral by setting NRFX_SPIM0_ENABLED, NRFX_SPIM_ENABLED to 0.

    Firstly, I found in the spi_master_using_nrf_spi_mngr that NRFX_SPIM_ENABLED is set to 1. May I ask why is that so?

    Unfortunately the driver configuration is a bit complex for legacy reasons. Generally, as you use the nrf_drv driver API (legacy API), the configuration macros starting with NRFX_ are irrelevant. What happens is that the macros starting with SPI* take precedence. and when it comes to using SPI or SPIM peripheral, that is decided by the value of SPI0_USE_EASY_DMA for instance 0, SPI1_USE_EASY_DMA for instance 1, etc.

    (Note that the API is the same in both cases, and you typically want to use the SPIM peripheral as it uses DMA. The driver handles all the differences for you, but that is much more sensible in a real application as the CPU can do other work while the SPIM peripheral handles the transaction.)

    Secondly, when I debug the same example on nrf52840, I can see the registers for both SPIM0 and SPI0 being configured with the same pins. Which can be a problem as described in the nrf52840 Product specifications. The document clearly says that only one peripheral can be associated to a particular pin at one point of time. 

    I see explained this good. All peripherals with the same register base address share the same physical components, and cannot be used at the same time. It does not make sense to look at the register of the other with the same address etc.

    I will appreciate if you can provide full settings for sdk_config.h or anything else, to use SPI0/SPIM0 with and without EasyDMA as I am not able to find any documentation on that. 

    Just refer to the mentioned example and change the value of SPI0_USE_EASY_DMA. that is the only required change.

Children
No Data
Related