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

SPI Prbolem , Clock dosen't work

Why the SPI clk doesn't work, i checked using an oscilloscope :/ I also don't get any SPI interrupt and no data change in the RX buffer although I have wired MISO and MOSI

void vSensor_eInitSensor_Exe()
{
   /*Config SPI PINs*/
	  nrf_gpio_pin_set(SCLK_PIN); /*Initial state of CLK is High*/

      NRF_GPIO->PIN_CNF[SCLK_PIN] =
    (GPIO_PIN_CNF_DIR_Output        << GPIO_PIN_CNF_DIR_Pos)
  | (GPIO_PIN_CNF_INPUT_Connect     << GPIO_PIN_CNF_INPUT_Pos)
  | (GPIO_PIN_CNF_PULL_Disabled     << GPIO_PIN_CNF_PULL_Pos)
  | (GPIO_PIN_CNF_DRIVE_S0S1        << GPIO_PIN_CNF_DRIVE_Pos)
  | (GPIO_PIN_CNF_SENSE_Disabled    << GPIO_PIN_CNF_SENSE_Pos);
  // - MOSI (optional) - output with initial value 0,
      nrf_gpio_pin_clear(MOSI_PIN);
    nrf_gpio_cfg_output(MOSI_PIN);
  /* - MISO (mandatory) - input*/
  nrf_gpio_cfg_input(MISO_PIN, NRF_GPIO_PIN_NOPULL);
  /*Init SPI*/
  nrf_spim_pins_set(&stSPI_iNRF_SPI_Type,(uint32_t )SCLK_PIN, MOSI_PIN,(uint32_t )MISO_PIN);
  nrf_spim_frequency_set(&stSPI_iNRF_SPI_Type,NRF_SPIM_FREQ_125K);
  nrf_spim_configure(&stSPI_iNRF_SPI_Type,NRF_SPIM_MODE_0,CstSPI_iNrfSpiBitOrder);
  nrf_spim_rx_buffer_set(&stSPI_iNRF_SPI_Type,ui8RxBuffer,SPI_RX_BYTES_NB);
  nrf_spim_tx_buffer_set(&stSPI_iNRF_SPI_Type,ui8TxBuffer/*NULL*/,SPI_RX_BYTES_NB);
  nrf_spim_int_enable(&stSPI_iNRF_SPI_Type,NRF_SPIM_INT_STOPPED_MASK|NRF_SPIM_INT_ENDRX_MASK|NRF_SPIM_INT_STARTED_MASK); /*get events when RX done*/
  nrf_spim_enable(&stSPI_iNRF_SPI_Type);
  nrf_drv_common_irq_enable(SPIM_IRQ ,SPIM_CONFIG_IRQ_PRIORITY); /*enable SPI0 interrupt */
	stSPI_iNRF_SPI_Type.POWER=1;
 /*Create Periodic task for reading*/ 
  vSensor_iCreateReadingTask_Exe();
}

Here is the periodic task of reading

static void vSensor_iPeriodicReadHandler_Exe(void * p_context)
{
	 if(false==nrf_drv_gpiote_in_is_set(MISO_PIN))
	 { 
		 /*Clear interrupt flags & Lunch read transaction*/
		 nrf_spim_event_clear(&stSPI_iNRF_SPI_Type,NRF_SPIM_EVENT_ENDRX);
		 nrf_spim_task_trigger(&stSPI_iNRF_SPI_Type,NRF_SPIM_TASK_START);
		 app_timer_start(m_conversion_read_timer_id, PERIODIC_READING_INTERVAL, NULL);
	 }
	 else
	 {
		 /*empty else*/
	 }
	 
}
  • Do I have to use SPIM structure? I think I need only SPI , because SPIM uses DMA. Can that be a rpoblem ? Hey I told you in the last comments that it works with the driver layer implemented by NORDIC but not mine. I copied all same way..initialization ..I am really confused.

    I used also SPI structure,,,not SPIM but nothing new!!

  • What do you mean by : with the interrupt handler from SPI driver?

  • The interrupt handler from the SPI driver: I did not define my own interrupt handler (this would also crete multiple definitions unless I removed the the SPI driver files (nrf_drv_spi.c) or removed the interrupt handler in the spi driver).

    You don't have to use the SPIM structure. You can choose between the SPIM and SPI peripheral on nRF52.

    Why do you not want to use the nordic driver? The error with bsp_btn_ble_on_ble_evt(..) was probably just pin conflicts between the SPI you set up and the buttons or LEDs the BSP module uses.

    Also: When I tested I ran these to lines in the while loop in main with some delay after (e.g. nrf_delay_ms(1000)):

    nrf_spim_event_clear(&stSPI_iNRF_SPI_Type,NRF_SPIM_EVENT_ENDRX);
    nrf_spim_task_trigger(&stSPI_iNRF_SPI_Type,NRF_SPIM_TASK_START);
    
  • Ok thanks for your help. I didn't succeed to use my function and my own driver. So I will , as I have to finish this project, to use Nordic driver . Thanks for your help again although i didn't exactly why my driver didn't run.

Related