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

SPI dependent on softdevice?

Hi, I am trying to combine SPI, microESB and BLE. BLE and microESB will not be combined in realtime, but rather be two distinct modes, and not run at the same time, and therefore entirely separated.

My question is: What should I watch out for? I have seen that NRF_POWER can't be used directly while the soft device is active. Is SPI doing something with the softdevice if I have SOFTDEVICE_PRESENT in the preprocessor? SPI initialization hangs unless I do:

SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);

If I only do instead:

NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

It will not come past the SPI initialization (spi_master_open).

I also use app_timer_init (APP_TIMER_INIT), nrf_drv_gpiote_init, GPIOTE_CONFIG_OUT_SIMPLE, set_gpiote_handler, set_wake_on_irq_handler.

Seems like APP_ERROR_CHECK(sd_nvic_ClearPendingIRQ(p_spi_instance->irq_type)); is the one in spi_master.c

Do I have to use timeslot API to combine microESB library and SPI?

  • SPI and softdevice are not doing anything with each other. SPI slave will not work along with softdevice, because softdevice will interrupt SPI slave handling which Master will not know and hence there will be loss of data.

    SPI Master with softdevice should work OK, because it is master that is driving the clock, so it should be ok even if softdevice interrupts its handling.

    You code cannot configure LFCLK while using softdevice, because that clock is will be owned by SD.

    Seems like APP_ERROR_CHECK(sd_nvic_ClearPendingIRQ(p_spi_instance->irq_type)); is the one in spi_master.c

    What is the error code? did you initialize SD before that? did it return without errors?

  • I did not initialize sd, that is the whole point. Because I don't want softdevice involved when working with microESB, because then I would need timeslot API.

    I upgraded to SDK 10, and now SPI works without softdevice, but microESB does not.

    sd_ functions cannot be called if the softdevice is not initialize, and you can't use NRF_ stuff directly when the softdevice is enabled.

  • Now both SPI and ESB work, when I initialized both HF and LF clock. My question then is should I power them down when powering off?

    NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    
  • Explicitly enabling them means that you need to explicitly power them down. So Yes

Related