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

SPI event handler not beeing called

Hi I am currently runnign into a problem that my SPI driver does not fire a spi_event after a while.

The code is as follows:

static volatile bool spi_xfer_done;

void spi_event_handler(nrf_drv_spi_evt_t const *p_event,
                       void *p_context)
{
    spi_xfer_done = true;
}

void spi_data_write(unsigned char data)
{
    uint8_t rx;
    spi_xfer_done = false;
    nrf_gpio_pin_set(DISPLAY_DC); // DC = 1 for data packet
    nrf_drv_spi_transfer(&spi, &data, 1, &rx, 0);

    // hang in there
    while (!spi_xfer_done)
    {
        __WFE();
    }
    return;
}

void spi_init()
{
    // init SPI
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin = DISPLAY_CS; // NRF_DRV_SPI_PIN_NOT_USED;
    spi_config.mosi_pin = DISPLAY_SDI;
    spi_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED;
    spi_config.sck_pin = DISPLAY_SCLK;
    spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
    spi_config.mode = NRF_DRV_SPI_MODE_0;
    spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
    nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);
}

The thing is, it is working at first. My main function is as follows:

static void bsp_event_handler(bsp_event_t event)
{
    switch (event)
    {
    case BSP_EVENT_KEY_3: // Button 4 pushed.
        NRF_LOG_INFO("Button 4 pressed");
        buttons |= 0x8;
        display_clear(&dsp, COLOR_WHITE);
        display_rect_fill(&dsp, 70, 70, 10, 10, COLOR_BLACK);
        display_render(&dsp);
        break;

    default:
        NRF_LOG_INFO("Button pressed");
        break;
    }
}


int main(void)
{
    char loop;
    // initialize logger
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    lfclk_config();
    NRF_LOG_INFO("LFClock init done");
    NRF_LOG_FLUSH();
    APP_ERROR_CHECK(app_timer_init());
    timer_interrupt_init();

    nrf_pwr_mgmt_init();

    APP_ERROR_CHECK(bsp_init(BSP_INIT_BUTTONS, bsp_event_handler));

    // initalize the display
    NRF_LOG_INFO("initialize display");
    display_init(&dsp);
    // draw splash screen
    NRF_LOG_INFO("draw splash");
    sw_splashscreen(&dsp);
    display_render(&dsp);
    APP_ERROR_CHECK(app_timer_start(m_timer, APP_TIMER_TICKS(5000), NULL));

    while (true)
    {
        NRF_LOG_INFO("loop: %d", loop++);
        NRF_LOG_FLUSH();
        app_sched_execute();
        nrf_pwr_mgmt_run();
    }
}

It works at first, the diosplay is switched on and displays the slapsh image as intendet in main. But everything after that using the SPI transfer function casues to infinite loop in 

while (!spi_xfer_done)
what might cause this behaviour?
Related