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

Crashing during the SPI transfer on NRF52810

Hi,

The program will crash when spi transfer on NRF52810. The crash occurs in spim_xfer  function, immediately after spim_int_enable function calling,

but if i remove the handler when spi init, it will not crash. I want to know what's going on and how to solve this problem, the spi is very important for me.

And this is my project's sdk_config.h,and the sdk version is nRF5_SDK_15.0.0_a53641a. Did I miss something.

Thanks.

Parents
  • Hi,

    Have you tried debugging the application, to see if any error codes are reported from the functions?

    If this does not help, please upload code showing how you initialize and configure the SPIM peripheral. Are you using the NRFX_SPIM driver in the SDK?

    Best regards,
    Jørgen

  • Hi,

    I debug the code, and the crash occurs after the spim_int_enable function calling.

    It is invalid whether I enable NRFX_SPIM driver or not.

    Tanks.

    Best regards.

    These are my spi config:

    #ifndef SPI_SS_PIN
    #define SPI_SS_PIN 14
    #endif
    
    #ifndef SPI_MISO_PIN
    #define SPI_MISO_PIN 18
    #endif
    
    #ifndef SPI_MOSI_PIN
    #define SPI_MOSI_PIN 15
    #endif
    
    #ifndef SPI_SCK_PIN
    #define SPI_SCK_PIN 13
    #endif
    
    
    // <e> NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
    //==========================================================
    #ifndef NRFX_SPIM_ENABLED
    #define NRFX_SPIM_ENABLED 1
    #endif
    // <q> NRFX_SPIM0_ENABLED  - Enable SPIM0 instance
     
    
    #ifndef NRFX_SPIM0_ENABLED
    #define NRFX_SPIM0_ENABLED 1
    #endif
    
    // <q> NRFX_SPIM1_ENABLED  - Enable SPIM1 instance
     
    
    #ifndef NRFX_SPIM1_ENABLED
    #define NRFX_SPIM1_ENABLED 0
    #endif
    
    // <q> NRFX_SPIM2_ENABLED  - Enable SPIM2 instance
     
    
    #ifndef NRFX_SPIM2_ENABLED
    #define NRFX_SPIM2_ENABLED 0
    #endif
    
    // <o> NRFX_SPIM_MISO_PULL_CFG  - MISO pin pull configuration.
     
    // <0=> NRF_GPIO_PIN_NOPULL 
    // <1=> NRF_GPIO_PIN_PULLDOWN 
    // <3=> NRF_GPIO_PIN_PULLUP 
    
    #ifndef NRFX_SPIM_MISO_PULL_CFG
    #define NRFX_SPIM_MISO_PULL_CFG 1
    #endif
    
    // <o> NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <e> NRFX_SPIM_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_SPIM_CONFIG_LOG_ENABLED
    #define NRFX_SPIM_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_SPIM_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_SPIM_CONFIG_LOG_LEVEL
    #define NRFX_SPIM_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_SPIM_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPIM_CONFIG_INFO_COLOR
    #define NRFX_SPIM_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_SPIM_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPIM_CONFIG_DEBUG_COLOR
    #define NRFX_SPIM_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // <q> NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED  - Enables nRF52 anomaly 109 workaround for SPIM.
     
    
    // <i> The workaround uses interrupts to wake up the CPU by catching
    // <i> a start event of zero-length transmission to start the clock. This 
    // <i> ensures that the DMA transfer will be executed without issues and
    // <i> that the proper transfer will be started. See more in the Errata 
    // <i> document or Anomaly 109 Addendum located at 
    // <i> https://infocenter.nordicsemi.com/
    
    #ifndef NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED
    #define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0
    #endif
    
    // </e>
    
    // <e> NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
    //==========================================================
    #ifndef NRFX_SPI_ENABLED
    #define NRFX_SPI_ENABLED 0
    #endif
    // <q> NRFX_SPI0_ENABLED  - Enable SPI0 instance
     
    
    #ifndef NRFX_SPI0_ENABLED
    #define NRFX_SPI0_ENABLED 1
    #endif
    
    // <q> NRFX_SPI1_ENABLED  - Enable SPI1 instance
     
    
    #ifndef NRFX_SPI1_ENABLED
    #define NRFX_SPI1_ENABLED 0
    #endif
    
    // <q> NRFX_SPI2_ENABLED  - Enable SPI2 instance
     
    
    #ifndef NRFX_SPI2_ENABLED
    #define NRFX_SPI2_ENABLED 0
    #endif
    
    // <o> NRFX_SPI_MISO_PULL_CFG  - MISO pin pull configuration.
     
    // <0=> NRF_GPIO_PIN_NOPULL 
    // <1=> NRF_GPIO_PIN_PULLDOWN 
    // <3=> NRF_GPIO_PIN_PULLUP 
    
    #ifndef NRFX_SPI_MISO_PULL_CFG
    #define NRFX_SPI_MISO_PULL_CFG 1
    #endif
    
    // <o> NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <e> NRFX_SPI_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_SPI_CONFIG_LOG_ENABLED
    #define NRFX_SPI_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_SPI_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_SPI_CONFIG_LOG_LEVEL
    #define NRFX_SPI_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_SPI_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_INFO_COLOR
    #define NRFX_SPI_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_SPI_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_DEBUG_COLOR
    #define NRFX_SPI_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    
    // <e> NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
    //==========================================================
    #ifndef NRFX_SPI_ENABLED
    #define NRFX_SPI_ENABLED 0
    #endif
    // <q> NRFX_SPI0_ENABLED  - Enable SPI0 instance
     
    
    #ifndef NRFX_SPI0_ENABLED
    #define NRFX_SPI0_ENABLED 1
    #endif
    
    // <q> NRFX_SPI1_ENABLED  - Enable SPI1 instance
     
    
    #ifndef NRFX_SPI1_ENABLED
    #define NRFX_SPI1_ENABLED 0
    #endif
    
    // <q> NRFX_SPI2_ENABLED  - Enable SPI2 instance
     
    
    #ifndef NRFX_SPI2_ENABLED
    #define NRFX_SPI2_ENABLED 0
    #endif
    
    // <o> NRFX_SPI_MISO_PULL_CFG  - MISO pin pull configuration.
     
    // <0=> NRF_GPIO_PIN_NOPULL 
    // <1=> NRF_GPIO_PIN_PULLDOWN 
    // <3=> NRF_GPIO_PIN_PULLUP 
    
    #ifndef NRFX_SPI_MISO_PULL_CFG
    #define NRFX_SPI_MISO_PULL_CFG 1
    #endif
    
    // <o> NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <e> NRFX_SPI_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_SPI_CONFIG_LOG_ENABLED
    #define NRFX_SPI_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_SPI_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_SPI_CONFIG_LOG_LEVEL
    #define NRFX_SPI_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_SPI_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_INFO_COLOR
    #define NRFX_SPI_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_SPI_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_DEBUG_COLOR
    #define NRFX_SPI_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // </e>
    // </e>

    And these are my initialize code.

    #include "nrf_drv_spi.h"
    #include "hal_spi.h"
    #include "nrf_drv_systick.h"
    #include "FreeRTOS.h"
    #include "semphr.h"
    #include "projdefs.h"
    #include "hal_uart.h"
    #include "nrf_gpiote.h"
    #include "nrf_gpio.h"
    #include "nrf_drv_gpiote.h"
    
    static const nrf_drv_spi_t nfc_spi = NRF_DRV_SPI_INSTANCE(NFC_SPI_INSTANCE); 
    SemaphoreHandle_t Spi_SemaphoreHanlde;
    uint8_t nfc_flag = 0x00;
    
    static void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void * p_context);
    
    
    
    
    
    static void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void * p_context)
    {
    	if(p_event -> type == NRF_DRV_SPI_EVENT_DONE)
    	{
    		BaseType_t yield_req = pdFALSE;
    		UNUSED_VARIABLE(xSemaphoreGiveFromISR(Spi_SemaphoreHanlde, &yield_req));
    		portYIELD_FROM_ISR(yield_req);	
    	}
    }
    
    
    void hal_spi_init()
    {
    	//SPI_SS_PIN;NRF_DRV_SPI_PIN_NOT_USED
    	//spi_config.mode = NRF_DRV_SPI_MODE_1;	  7970
    	//spi_config.mode = NRF_DRV_SPI_MODE_0;	  7963
    	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;
    	spi_config.frequency  = NRF_DRV_SPI_FREQ_2M;
    	spi_config.mode = NRF_DRV_SPI_MODE_1; 	
    	APP_ERROR_CHECK(nrf_drv_spi_init(&nfc_spi, &spi_config, spi_event_handler, NULL));
    
    	Spi_SemaphoreHanlde = xSemaphoreCreateBinary();
    	ASSERT(Spi_SemaphoreHanlde!=NULL);
    
    }
    
    void hal_spi_transfer(uint8_t *tx_buffer,uint8_t tx_length,uint8_t *rx_buffer,uint8_t rx_length)
    {
    	APP_ERROR_CHECK(nrf_drv_spi_transfer(&nfc_spi, tx_buffer, tx_length, rx_buffer, rx_length));
    	TickType_t xMaxExpectedBlockTime  = pdMS_TO_TICKS( 10 );
    	UNUSED_RETURN_VALUE(xSemaphoreTake(Spi_SemaphoreHanlde, xMaxExpectedBlockTime));
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

Reply
  • Hi,

    I debug the code, and the crash occurs after the spim_int_enable function calling.

    It is invalid whether I enable NRFX_SPIM driver or not.

    Tanks.

    Best regards.

    These are my spi config:

    #ifndef SPI_SS_PIN
    #define SPI_SS_PIN 14
    #endif
    
    #ifndef SPI_MISO_PIN
    #define SPI_MISO_PIN 18
    #endif
    
    #ifndef SPI_MOSI_PIN
    #define SPI_MOSI_PIN 15
    #endif
    
    #ifndef SPI_SCK_PIN
    #define SPI_SCK_PIN 13
    #endif
    
    
    // <e> NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
    //==========================================================
    #ifndef NRFX_SPIM_ENABLED
    #define NRFX_SPIM_ENABLED 1
    #endif
    // <q> NRFX_SPIM0_ENABLED  - Enable SPIM0 instance
     
    
    #ifndef NRFX_SPIM0_ENABLED
    #define NRFX_SPIM0_ENABLED 1
    #endif
    
    // <q> NRFX_SPIM1_ENABLED  - Enable SPIM1 instance
     
    
    #ifndef NRFX_SPIM1_ENABLED
    #define NRFX_SPIM1_ENABLED 0
    #endif
    
    // <q> NRFX_SPIM2_ENABLED  - Enable SPIM2 instance
     
    
    #ifndef NRFX_SPIM2_ENABLED
    #define NRFX_SPIM2_ENABLED 0
    #endif
    
    // <o> NRFX_SPIM_MISO_PULL_CFG  - MISO pin pull configuration.
     
    // <0=> NRF_GPIO_PIN_NOPULL 
    // <1=> NRF_GPIO_PIN_PULLDOWN 
    // <3=> NRF_GPIO_PIN_PULLUP 
    
    #ifndef NRFX_SPIM_MISO_PULL_CFG
    #define NRFX_SPIM_MISO_PULL_CFG 1
    #endif
    
    // <o> NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <e> NRFX_SPIM_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_SPIM_CONFIG_LOG_ENABLED
    #define NRFX_SPIM_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_SPIM_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_SPIM_CONFIG_LOG_LEVEL
    #define NRFX_SPIM_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_SPIM_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPIM_CONFIG_INFO_COLOR
    #define NRFX_SPIM_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_SPIM_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPIM_CONFIG_DEBUG_COLOR
    #define NRFX_SPIM_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // <q> NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED  - Enables nRF52 anomaly 109 workaround for SPIM.
     
    
    // <i> The workaround uses interrupts to wake up the CPU by catching
    // <i> a start event of zero-length transmission to start the clock. This 
    // <i> ensures that the DMA transfer will be executed without issues and
    // <i> that the proper transfer will be started. See more in the Errata 
    // <i> document or Anomaly 109 Addendum located at 
    // <i> https://infocenter.nordicsemi.com/
    
    #ifndef NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED
    #define NRFX_SPIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0
    #endif
    
    // </e>
    
    // <e> NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
    //==========================================================
    #ifndef NRFX_SPI_ENABLED
    #define NRFX_SPI_ENABLED 0
    #endif
    // <q> NRFX_SPI0_ENABLED  - Enable SPI0 instance
     
    
    #ifndef NRFX_SPI0_ENABLED
    #define NRFX_SPI0_ENABLED 1
    #endif
    
    // <q> NRFX_SPI1_ENABLED  - Enable SPI1 instance
     
    
    #ifndef NRFX_SPI1_ENABLED
    #define NRFX_SPI1_ENABLED 0
    #endif
    
    // <q> NRFX_SPI2_ENABLED  - Enable SPI2 instance
     
    
    #ifndef NRFX_SPI2_ENABLED
    #define NRFX_SPI2_ENABLED 0
    #endif
    
    // <o> NRFX_SPI_MISO_PULL_CFG  - MISO pin pull configuration.
     
    // <0=> NRF_GPIO_PIN_NOPULL 
    // <1=> NRF_GPIO_PIN_PULLDOWN 
    // <3=> NRF_GPIO_PIN_PULLUP 
    
    #ifndef NRFX_SPI_MISO_PULL_CFG
    #define NRFX_SPI_MISO_PULL_CFG 1
    #endif
    
    // <o> NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <e> NRFX_SPI_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_SPI_CONFIG_LOG_ENABLED
    #define NRFX_SPI_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_SPI_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_SPI_CONFIG_LOG_LEVEL
    #define NRFX_SPI_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_SPI_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_INFO_COLOR
    #define NRFX_SPI_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_SPI_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_DEBUG_COLOR
    #define NRFX_SPI_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    
    // <e> NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
    //==========================================================
    #ifndef NRFX_SPI_ENABLED
    #define NRFX_SPI_ENABLED 0
    #endif
    // <q> NRFX_SPI0_ENABLED  - Enable SPI0 instance
     
    
    #ifndef NRFX_SPI0_ENABLED
    #define NRFX_SPI0_ENABLED 1
    #endif
    
    // <q> NRFX_SPI1_ENABLED  - Enable SPI1 instance
     
    
    #ifndef NRFX_SPI1_ENABLED
    #define NRFX_SPI1_ENABLED 0
    #endif
    
    // <q> NRFX_SPI2_ENABLED  - Enable SPI2 instance
     
    
    #ifndef NRFX_SPI2_ENABLED
    #define NRFX_SPI2_ENABLED 0
    #endif
    
    // <o> NRFX_SPI_MISO_PULL_CFG  - MISO pin pull configuration.
     
    // <0=> NRF_GPIO_PIN_NOPULL 
    // <1=> NRF_GPIO_PIN_PULLDOWN 
    // <3=> NRF_GPIO_PIN_PULLUP 
    
    #ifndef NRFX_SPI_MISO_PULL_CFG
    #define NRFX_SPI_MISO_PULL_CFG 1
    #endif
    
    // <o> NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <e> NRFX_SPI_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_SPI_CONFIG_LOG_ENABLED
    #define NRFX_SPI_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_SPI_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_SPI_CONFIG_LOG_LEVEL
    #define NRFX_SPI_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_SPI_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_INFO_COLOR
    #define NRFX_SPI_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_SPI_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_SPI_CONFIG_DEBUG_COLOR
    #define NRFX_SPI_CONFIG_DEBUG_COLOR 0
    #endif
    
    // </e>
    
    // </e>
    // </e>

    And these are my initialize code.

    #include "nrf_drv_spi.h"
    #include "hal_spi.h"
    #include "nrf_drv_systick.h"
    #include "FreeRTOS.h"
    #include "semphr.h"
    #include "projdefs.h"
    #include "hal_uart.h"
    #include "nrf_gpiote.h"
    #include "nrf_gpio.h"
    #include "nrf_drv_gpiote.h"
    
    static const nrf_drv_spi_t nfc_spi = NRF_DRV_SPI_INSTANCE(NFC_SPI_INSTANCE); 
    SemaphoreHandle_t Spi_SemaphoreHanlde;
    uint8_t nfc_flag = 0x00;
    
    static void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void * p_context);
    
    
    
    
    
    static void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void * p_context)
    {
    	if(p_event -> type == NRF_DRV_SPI_EVENT_DONE)
    	{
    		BaseType_t yield_req = pdFALSE;
    		UNUSED_VARIABLE(xSemaphoreGiveFromISR(Spi_SemaphoreHanlde, &yield_req));
    		portYIELD_FROM_ISR(yield_req);	
    	}
    }
    
    
    void hal_spi_init()
    {
    	//SPI_SS_PIN;NRF_DRV_SPI_PIN_NOT_USED
    	//spi_config.mode = NRF_DRV_SPI_MODE_1;	  7970
    	//spi_config.mode = NRF_DRV_SPI_MODE_0;	  7963
    	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;
    	spi_config.frequency  = NRF_DRV_SPI_FREQ_2M;
    	spi_config.mode = NRF_DRV_SPI_MODE_1; 	
    	APP_ERROR_CHECK(nrf_drv_spi_init(&nfc_spi, &spi_config, spi_event_handler, NULL));
    
    	Spi_SemaphoreHanlde = xSemaphoreCreateBinary();
    	ASSERT(Spi_SemaphoreHanlde!=NULL);
    
    }
    
    void hal_spi_transfer(uint8_t *tx_buffer,uint8_t tx_length,uint8_t *rx_buffer,uint8_t rx_length)
    {
    	APP_ERROR_CHECK(nrf_drv_spi_transfer(&nfc_spi, tx_buffer, tx_length, rx_buffer, rx_length));
    	TickType_t xMaxExpectedBlockTime  = pdMS_TO_TICKS( 10 );
    	UNUSED_RETURN_VALUE(xSemaphoreTake(Spi_SemaphoreHanlde, xMaxExpectedBlockTime));
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

Children
No Data
Related