problem with serial flash memory interface

Hi,

My board is using nRF52805.
I am trying to interface SPI interface serial flash.

I modified the sdk_config.h file.

My code is as bellow.

Code is stuck in nrf_drv_spi_init();
When I put the debug message in nrf_drv_spi_init(), like printf("nrf_drv_spi_init\n") in font of the function, but only "nr" is printed and hang on.

If I skip this function W25qxx_init(), next codes are working well, advertising, connecting, ....

BR
Paul

-------

void
W25qxx_init (void)
{
  APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
  NRF_LOG_DEFAULT_BACKENDS_INIT();

  nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
  spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
  spi_config.mode = NRF_DRV_SPI_MODE_1;
  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;

  nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);

  nrf_gpio_cfg_output(SPI_SS_PIN);
  nrf_gpio_pin_set (SPI_SS_PIN);

  W25qxx_ReadID ();
}
  • Hello Sangdo Lee,

    Thank you for contacting DevZone at NordicSemi.

    The spi initializer function would take the driver instance, initial configurations, handler function, and the context passed to event handler

    ret_code_t nrf_drv_spi_init	(   nrf_drv_spi_t const *const 	    p_instance,
                                    nrf_drv_spi_config_t const * 	p_config,
                                    nrf_drv_spi_evt_handler_t 	    handler,
                                    void * 	                        p_context 
                                )

    The function would return the code with one of the following values:

    NRF_SUCCESS	If initialization was successful
    NRF_ERROR_INVALID_STATE	If the driver was already initialized
    NRF_ERROR_BUSY	If some other peripheral with the same instance ID is already in use

    I suggest not to put printk() and/or any kind of debugging / logging statements in the initializer function and rather check what value the function is returning in your main code.

    Here is an example of checking return value in the nrf5 sdk17.1.0 in the /peripheral/spi/ sample:

    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

    BR,

    Naeem

  • Hi,

    I found that nrf_drv_spi_init() in the example of /peripheral/spi, does return success result.
    But my call nrf_drv_spi_init() does not return anything one, stucking in rnf_drv_spi_init().

    The example of /peripheral/spi does not use softdevice, but my app use softdevice.
    Is it can be a reason of stucking in nrf_drv_spi_init();?

    BR
    Paul

  • Hi Paul,

    That should not be a problem

    You may combine spi and ble related code from relevant examples. 

Related