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

Unable to assign an SPI End Event to a DPPI channel on nRF5340dk

Hi, everyone,

I'm trying to assign an SPI End Event to a DPPI channel on nRF5340dk to trigger a counter automatically. However, the value of the counter never increases.

If I assign the count task of the counter to a GPIOTE in event, the counter value increases successfully. So I think the assignment of the SPI End Event must have something wrong.

Here's part of my code:

   

nrfx_spim_t               spi         =   NRFX_SPIM_INSTANCE(4);
nrfx_timer_t              spi_counter =   NRFX_TIMER_INSTANCE(2);


uint8_t  dppi_channel_drdy;
uint8_t  dppi_channel_spi_end;


void gpiote_in_init(void)
{
    if ( nrfx_gpiote_is_init() == false )
	{
		IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
		    DT_IRQ(DT_NODELABEL(gpiote), priority),
		    nrfx_isr, nrfx_gpiote_irq_handler, 0);

		nrfx_err_t err = nrfx_gpiote_init(0);

		if (err != NRFX_SUCCESS) {
			printk("nrfx_gpiote_init error: %08x \n", err); 
			return m_rx_buf;
		}
	}
	
	// err_code
	nrfx_err_t err;
        
    // gpiote in: DRDY_PIN - hitolo
	nrfx_gpiote_in_config_t config_in_hitolo = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
	err = nrfx_gpiote_in_init(GPIOTE_PIN, &config_in_hitolo, NULL);
	
	if (err != NRFX_SUCCESS)
		printk("DRDY_init error: %08x \n", err); 
}


void spi_init(void)
{
	// err_code
	nrfx_err_t err;

    //SPI 
	/*   
    IRQ_DIRECT_CONNECT(SPIM4_IRQn, 0,
			   nrfx_spim_4_irq_handler, 0);
	irq_enable(SPIM4_IRQn);
	*/
        

	nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG(SCK_PIN, MOSI_PIN, MISO_PIN, NRFX_SPIM_PIN_NOT_USED);
	spi_config.mode = NRF_SPIM_MODE_1;
	spi_config.frequency = NRF_SPIM_FREQ_2M;
	err = nrfx_spim_init(&spi, &spi_config, NULL, NULL);

    NRF_SPIM4->PSEL.CSN = CS_PIN;

	if (err != NRFX_SUCCESS)
		printk("spi_driver_init error: %08x \n", err); 
}


void spi_counter_init(void)
{
    IRQ_CONNECT(DT_IRQN(DT_NODELABEL(timer2)),
		    DT_IRQ(DT_NODELABEL(timer2), priority),
		    nrfx_isr, nrfx_timer_2_irq_handler, 0);

    nrfx_timer_config_t counter_cfg     	=   NRFX_TIMER_DEFAULT_CONFIG;
	counter_cfg.mode                    	=   NRF_TIMER_MODE_COUNTER;
	counter_cfg.bit_width                   =   NRF_TIMER_BIT_WIDTH_32;

    nrfx_timer_uninit(&spi_counter);
	nrfx_err_t err = nrfx_timer_init(&spi_counter, &counter_cfg, spi_counter_event_handler);
	if (err != NRFX_SUCCESS)
		printk("spi_counter_init error: %08x \n", err); 
}


void dppi_init(void)
{

    //dppi channel 1: drdy->spi start
	nrfx_err_t err = nrfx_dppi_channel_alloc(&dppi_channel_drdy);
	if (err != NRFX_SUCCESS)
		printk("dppi1_init error: %08x \n", err); 
		
	nrf_gpiote_publish_set(NRF_GPIOTE, nrfx_gpiote_in_event_get(GPIOTE_PIN), dppi_channel_drdy);
    nrf_spim_subscribe_set(NRF_SPIM4, nrfx_spim_start_task_get(&spi), dppi_channel_drdy);
    //nrf_timer_subscribe_set(NRF_TIMER2, NRF_TIMER_TASK_COUNT, dppi_channel_drdy);
        

    err = nrfx_dppi_channel_enable(dppi_channel_drdy);
	if (err != NRFX_SUCCESS)
		printk("dppi1_enable error: %08x \n", err);


    //dppi channel 2: spi_end->counter + 1
    err = nrfx_dppi_channel_alloc(&dppi_channel_spi_end);
	if (err != NRFX_SUCCESS)
		printk("dppi2_init error: %08x \n", err); 
	
    nrf_spim_publish_set(NRF_SPIM4, nrfx_spim_end_event_get(&spi), dppi_channel_spi_end);
    nrf_timer_subscribe_set(NRF_TIMER2, NRF_TIMER_TASK_COUNT, dppi_channel_spi_end);     

    err = nrfx_dppi_channel_enable(dppi_channel_spi_end);
	if (err != NRFX_SUCCESS)
		printk("dppi2_enable error: %08x \n", err);
	     
}


void main(void){
    gpiote_in_init();
    spi_init();
    spi_counter_init();
    dppi_init();
    
    //......
}

Also, the GPIOTE  in event can trigger the spi start task successfully. 

So I wonder if there are additionly steps to assign an SPI End Event to a DPPI channel.

Parents Reply Children
No Data
Related