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*/
}
}