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

If delay is inserted after data transmission by SPI, it transits to default_handler

Hi!

I am planning to port SPI sending and receiving functions to the sample code of ble_app_uart of SDK 14.0.0.

The transplant was finish, but when I am debugging,if I add a delay after sending data with SPI while debugging, it will transition to Default_handler.

The code running SPI and UART worked fine without problems.

Is it impossible to put a delay in ble's sample code?

best regards!!

void SPITxCommand(unsigned char Data)
{
nrf_gpio_pin_clear(22); //CS pin low
nrf_drv_spi_transfer(&spi, &Data, 1, NULL, NULL);
//nrf_delay_us(50);
nrf_delay_us(100); //error component
}

 

  • thank you for your reply!

    This code has the function of BLE, we use it to confirm data transmission with smartphone.

    I added the function from SPI sample code, but added the following function to config.h.

     

    // <h> Application 
    
    //==========================================================
    // <h> SPI_CONFIGURATION - Spi configuration
    
    //==========================================================
    // <o> SPI_SCK_PIN  - Pin number
     
    // <0=> 0 (P0.0) 
    // <1=> 1 (P0.1) 
    // <2=> 2 (P0.2) 
    // <3=> 3 (P0.3) 
    // <4=> 4 (P0.4) 
    // <5=> 5 (P0.5) 
    // <6=> 6 (P0.6) 
    // <7=> 7 (P0.7) 
    // <8=> 8 (P0.8) 
    // <9=> 9 (P0.9) 
    // <10=> 10 (P0.10) 
    // <11=> 11 (P0.11) 
    // <12=> 12 (P0.12) 
    // <13=> 13 (P0.13) 
    // <14=> 14 (P0.14) 
    // <15=> 15 (P0.15) 
    // <16=> 16 (P0.16) 
    // <17=> 17 (P0.17) 
    // <18=> 18 (P0.18) 
    // <19=> 19 (P0.19) 
    // <20=> 20 (P0.20) 
    // <21=> 21 (P0.21) 
    // <22=> 22 (P0.22) 
    // <23=> 23 (P0.23) 
    // <24=> 24 (P0.24) 
    // <25=> 25 (P0.25) 
    // <26=> 26 (P0.26) 
    // <27=> 27 (P0.27) 
    // <28=> 28 (P0.28) 
    // <29=> 29 (P0.29) 
    // <30=> 30 (P0.30) 
    // <31=> 31 (P0.31) 
    // <4294967295=> Not connected 
    
    #ifndef SPI_SCK_PIN
    //#define SPI_SCK_PIN 3
    /*matsumiya*/
    #define SPI_SCK_PIN 24
    #endif
    
    // <o> SPI_MISO_PIN  - Pin number
     
    // <0=> 0 (P0.0) 
    // <1=> 1 (P0.1) 
    // <2=> 2 (P0.2) 
    // <3=> 3 (P0.3) 
    // <4=> 4 (P0.4) 
    // <5=> 5 (P0.5) 
    // <6=> 6 (P0.6) 
    // <7=> 7 (P0.7) 
    // <8=> 8 (P0.8) 
    // <9=> 9 (P0.9) 
    // <10=> 10 (P0.10) 
    // <11=> 11 (P0.11) 
    // <12=> 12 (P0.12) 
    // <13=> 13 (P0.13) 
    // <14=> 14 (P0.14) 
    // <15=> 15 (P0.15) 
    // <16=> 16 (P0.16) 
    // <17=> 17 (P0.17) 
    // <18=> 18 (P0.18) 
    // <19=> 19 (P0.19) 
    // <20=> 20 (P0.20) 
    // <21=> 21 (P0.21) 
    // <22=> 22 (P0.22) 
    // <23=> 23 (P0.23) 
    // <24=> 24 (P0.24) 
    // <25=> 25 (P0.25) 
    // <26=> 26 (P0.26) 
    // <27=> 27 (P0.27) 
    // <28=> 28 (P0.28) 
    // <29=> 29 (P0.29) 
    // <30=> 30 (P0.30) 
    // <31=> 31 (P0.31) 
    // <4294967295=> Not connected 
    
    #ifndef SPI_MISO_PIN
    //#define SPI_MISO_PIN 28
    /*matsumiya*/
    #define SPI_MISO_PIN 25
    #endif
    
    // <o> SPI_MOSI_PIN  - Pin number
     
    // <0=> 0 (P0.0) 
    // <1=> 1 (P0.1) 
    // <2=> 2 (P0.2) 
    // <3=> 3 (P0.3) 
    // <4=> 4 (P0.4) 
    // <5=> 5 (P0.5) 
    // <6=> 6 (P0.6) 
    // <7=> 7 (P0.7) 
    // <8=> 8 (P0.8) 
    // <9=> 9 (P0.9) 
    // <10=> 10 (P0.10) 
    // <11=> 11 (P0.11) 
    // <12=> 12 (P0.12) 
    // <13=> 13 (P0.13) 
    // <14=> 14 (P0.14) 
    // <15=> 15 (P0.15) 
    // <16=> 16 (P0.16) 
    // <17=> 17 (P0.17) 
    // <18=> 18 (P0.18) 
    // <19=> 19 (P0.19) 
    // <20=> 20 (P0.20) 
    // <21=> 21 (P0.21) 
    // <22=> 22 (P0.22) 
    // <23=> 23 (P0.23) 
    // <24=> 24 (P0.24) 
    // <25=> 25 (P0.25) 
    // <26=> 26 (P0.26) 
    // <27=> 27 (P0.27) 
    // <28=> 28 (P0.28) 
    // <29=> 29 (P0.29) 
    // <30=> 30 (P0.30) 
    // <31=> 31 (P0.31) 
    // <4294967295=> Not connected 
    
    #ifndef SPI_MOSI_PIN
    //#define SPI_MOSI_PIN 4
    /*matsumiya*/
    #define SPI_MOSI_PIN 23
    
    #endif
    
    // <o> SPI_SS_PIN  - Pin number
     
    // <0=> 0 (P0.0) 
    // <1=> 1 (P0.1) 
    // <2=> 2 (P0.2) 
    // <3=> 3 (P0.3) 
    // <4=> 4 (P0.4) 
    // <5=> 5 (P0.5) 
    // <6=> 6 (P0.6) 
    // <7=> 7 (P0.7) 
    // <8=> 8 (P0.8) 
    // <9=> 9 (P0.9) 
    // <10=> 10 (P0.10) 
    // <11=> 11 (P0.11) 
    // <12=> 12 (P0.12) 
    // <13=> 13 (P0.13) 
    // <14=> 14 (P0.14) 
    // <15=> 15 (P0.15) 
    // <16=> 16 (P0.16) 
    // <17=> 17 (P0.17) 
    // <18=> 18 (P0.18) 
    // <19=> 19 (P0.19) 
    // <20=> 20 (P0.20) 
    // <21=> 21 (P0.21) 
    // <22=> 22 (P0.22) 
    // <23=> 23 (P0.23) 
    // <24=> 24 (P0.24) 
    // <25=> 25 (P0.25) 
    // <26=> 26 (P0.26) 
    // <27=> 27 (P0.27) 
    // <28=> 28 (P0.28) 
    // <29=> 29 (P0.29) 
    // <30=> 30 (P0.30) 
    // <31=> 31 (P0.31) 
    // <4294967295=> Not connected 
    
    #ifndef SPI_SS_PIN
    //#define SPI_SS_PIN 29
    /*matsumiya*/
    #define SPI_SS_PIN 22
    #endif
    
    // <o> SPI_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef SPI_IRQ_PRIORITY
    /*matsumiya*/
    //#define SPI_IRQ_PRIORITY 7
    #define SPI_IRQ_PRIORITY 2
    #endif

    Is it a problem that you are using an SPI that is not in the selection frame of the default handler below?

    Default_Handler PROC
    
                    EXPORT   POWER_CLOCK_IRQHandler [WEAK]
                    EXPORT   RADIO_IRQHandler [WEAK]
                    EXPORT   UARTE0_UART0_IRQHandler [WEAK]
                    EXPORT   SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler [WEAK]
                    EXPORT   SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler [WEAK]
                    EXPORT   NFCT_IRQHandler [WEAK]
                    EXPORT   GPIOTE_IRQHandler [WEAK]
                    EXPORT   SAADC_IRQHandler [WEAK]
                    EXPORT   TIMER0_IRQHandler [WEAK]
                    EXPORT   TIMER1_IRQHandler [WEAK]
                    EXPORT   TIMER2_IRQHandler [WEAK]
                    EXPORT   RTC0_IRQHandler [WEAK]
                    EXPORT   TEMP_IRQHandler [WEAK]
                    EXPORT   RNG_IRQHandler [WEAK]
                    EXPORT   ECB_IRQHandler [WEAK]
                    EXPORT   CCM_AAR_IRQHandler [WEAK]
                    EXPORT   WDT_IRQHandler [WEAK]
                    EXPORT   RTC1_IRQHandler [WEAK]
                    EXPORT   QDEC_IRQHandler [WEAK]
                    EXPORT   COMP_LPCOMP_IRQHandler [WEAK]
                    EXPORT   SWI0_EGU0_IRQHandler [WEAK]
                    EXPORT   SWI1_EGU1_IRQHandler [WEAK]
                    EXPORT   SWI2_EGU2_IRQHandler [WEAK]
                    EXPORT   SWI3_EGU3_IRQHandler [WEAK]
                    EXPORT   SWI4_EGU4_IRQHandler [WEAK]
                    EXPORT   SWI5_EGU5_IRQHandler [WEAK]
                    EXPORT   TIMER3_IRQHandler [WEAK]
                    EXPORT   TIMER4_IRQHandler [WEAK]
                    EXPORT   PWM0_IRQHandler [WEAK]
                    EXPORT   PDM_IRQHandler [WEAK]
                    EXPORT   MWU_IRQHandler [WEAK]
                    EXPORT   PWM1_IRQHandler [WEAK]
                    EXPORT   PWM2_IRQHandler [WEAK]
                    EXPORT   SPIM2_SPIS2_SPI2_IRQHandler [WEAK]
                    EXPORT   RTC2_IRQHandler [WEAK]
                    EXPORT   I2S_IRQHandler [WEAK]
                    EXPORT   FPU_IRQHandler [WEAK]

    best regards!!

  • thank you for your reply!

    I will post the whole project with a drop box.

    Please confirm the following information

    www.dropbox.com/.../ble_app_uart_spiuart.zip

  • Hi!

    While doing debugging, I found that the next instruction using the nrf_drv_spi_transfer function transitions to default handler.

    Does that mean that ble's sample code has missing files such as SPI C files and libraries?

     best regards!

  • There is an error in your sdk_config.h file. You have set SPI0_ENABLED to 0 and SPI1_ENABLED to 1, but in your code you use SPI0 when declaring the SPI instance (NRF_DRV_SPI_INSTANCE(0)). The SPI0 IRQ handler is not compiled in and will default to the Default_Handler.

Related