SPI worked strangely(external SPI Fash)

Hi,

I am using custom board with nRF52832.In the custom board, there is a SPI flash to storage some data.

I can read or write the flash normally at the beginning,but whenI create a timer to read/write the flash, the SPI interface will never work normally again. The spi_xfer_done will never turn to true.

Before into for(;;), I can read/wirite the data normally in W25QXX_Init() or W25QXX_test().But when I create a 1s timer to read/write again(W25QXX_test()), the RTT Viewer will always print "SPI WRITE".

BTW, my application is based on examples\ble_peripheral\ble_app_uart\pca10040\s112 and I have closed the bspxx to avoid the conflict of GPIO. To find the reason of SPI error, I added LOG in SPI driver when create the timer.

Here is the application code.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main(void)
{
// bool erase_bonds;
// ret_code_t err_code;
// Initialize.
log_init();
// Initialize the async SVCI interface to bootloader before any interrupts are enabled.
// err_code = ble_dfu_buttonless_async_svci_init();
// APP_ERROR_CHECK(err_code);
timers_init();
// buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
// sd_power_dcdc_mode_set(NRF_POWER_DCDC_DISABLE);
gap_params_init();
gatt_init();
services_init();
advertising_init();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here is the SPI interface.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "w25qxx.h"
#include "nrf_drv_spi.h"
#include "nrf_delay.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#define SPI_INSTANCE 0 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
static volatile bool spi_xfer_done; /**< Flag used to indicate that SPI instance completed the transfer. */
uint16_t W25QXX_TYPE=W25Q128; //ĬÈÏÊÇW25Q128
uint8_t SPI_Tx_Buf[8];
uint8_t SPI_Rx_Buf[8];
volatile uint8_t SPIReadLength, SPIWriteLength;
/**
* @brief SPI user event handler.
* @param event
*/
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX