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

I want example timer + spi (SDK 14.2.0)

Hi, all.

I m trying to combine two example spi + timer using nRF52832.

But spi_event_handler function in the ex spi and timer event in the ex timer are crashed.  

If I insert source code "nrf_drv_timer_enable(&TIMER_TEST);", program is died.

I want to result this problem.

Can you help me?

source code is as below.

//const nrf_drv_timer_t TIMER_TEST = NRF_DRV_TIMER_INSTANCE(0);

/**
 * @brief SPI user event handler.
 * @param event
 */
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    spi_xfer_done = true;
   
//    NRF_LOG_INFO("Transfer completed.");
//    if (m_rx_buf[0] != 0)
//    {
//        NRF_LOG_INFO(" Received:");
//        NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
//    }  
}


///**
 * @brief Handler for timer events.
 */
void timer_event_handler(nrf_timer_event_t event_type, void* p_context)
{
}

int main(void)
{
    
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
   
    NRF_LOG_INFO("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));
   
    
    
    // Timer
    uint32_t time_ms = 1000; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    //Configure TIMER_BMS for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_TEST, &timer_cfg, timer_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_TEST, time_ms);

    nrf_drv_timer_extended_compare(
         &TIMER_BMS, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&TIMER_TEST);
   
    while (1)
    {
        spi_xfer_done = false;

        __WFE();
        __WFI();
       

       // nrf_drv_spi_transfer

              
       
        NRF_LOG_FLUSH();
    }
}

Parents Reply Children
No Data
Related