//SPI 1.0V

	/*
	When you call nrf_drv_spi_transfer(&m_spi_m, tx_buffer, tx_bytes, rx_buffer, rx_bytes), specify value for tx_bytes, it is the number of bytes you want to put on the SPI master-out pin; rx_bytes refers to the number of bytes you want to fill for the rx_buffer, beginning at the start of your transaction.
For example, a register read on a SPI peripheral requires first writing the address of register you want to read, SPI peripheral will return the value of that register as soon as you finish writing the address. In this case tx_bytes is 1, rx_bytes is 2. When the call completes with call back, you will get the read from rx_buffer[1].
In general, if you want to tx x bytes, and receive y bytes after x bytes has been transferred, rx_buffer needs to be the size of (x + y). A valid read back value will start at rx_buffer[x] for the length of y.
	重点：发送X个字节的数据，接受Y个字节的数据，则接收缓冲区至少有X+Y个字节的长度，而接收到的数据从rx_buffer[x]开始，长度为y。
	*/
	
	
/*********************************************************************
 * INCLUDES
 */
#include "bsp_spi.h"
#include "exception.h"
#include "system.h"

/*Private macro ----------------------------------------------------*/


static void spi0CallbackFunc(nrf_drv_spi_evt_t const *pEvent, void *arg);
static void spi1CallbackFunc(nrf_drv_spi_evt_t const *pEvent, void *arg);
static void spi2CallbackFunc(nrf_drv_spi_evt_t const *pEvent, void *arg);

/*********************************************************************
 * LOCAL VARIABLES
 */
static volatile bool 					s0_transferOk = true;  																	// SPI0数据传输完成标志
static volatile bool 					s1_transferOk = true;  																	// SPI1数据传输完成标志
static volatile bool 					s2_transferOk = true;  																	// SPI2数据传输完成标志

static const nrf_drv_spi_t 		s0_spiHandle = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE_0);		// SPI0 instance
static const nrf_drv_spi_t 		s1_spiHandle = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE_1);		// SPI1 instance
static const nrf_drv_spi_t 		s2_spiHandle = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE_2);		// SPI2 instance

static const uint8_t					s0_cs_list[SPI0_CS_NUMBER] = SPI0_CS_LIST;							// SPI0 片选列表
static const uint8_t					s1_cs_list[SPI1_CS_NUMBER] = SPI1_CS_LIST;							// SPI1 片选列表
static const uint8_t					s2_cs_list[SPI2_CS_NUMBER] = SPI2_CS_LIST;							// SPI2 片选列表


/*********************************************************************
 * LOCAL FUNCTIONS
 */
/**
 @brief SPI中断处理回调函数
 @param 无
 @return 无
*/
static void spi0CallbackFunc(nrf_drv_spi_evt_t const *pEvent, void *arg)
{
	//事件类型只有NRF_DRV_SPI_EVENT_DONE
	s0_transferOk = true;
}
static void spi1CallbackFunc(nrf_drv_spi_evt_t const *pEvent, void *arg)
{
	//事件类型只有NRF_DRV_SPI_EVENT_DONE
	s1_transferOk = true;
}
static void spi2CallbackFunc(nrf_drv_spi_evt_t const *pEvent, void *arg)
{
	//事件类型只有NRF_DRV_SPI_EVENT_DONE
	s2_transferOk = true;
}

/**
 @brief SPI片选引脚检查
 @param CsPin_number -[in] 片选引脚
 @return 错误代码
*/
static uint32_t SPI0_CsCheck(uint32_t CsPin_number)
{
	uint32_t i;
	
	for(i = 0; i < SPI0_CS_NUMBER; i++)
	{
		if(s0_cs_list[i] == CsPin_number)
			return SPI_OP_SUCCESS;
	}
	
	return SPI_ERROR_CS;
}
static uint32_t SPI1_CsCheck(uint32_t CsPin_number)
{
	uint32_t i;
	
	for(i = 0; i < SPI1_CS_NUMBER; i++)
	{
		if(s1_cs_list[i] == CsPin_number)
			return SPI_OP_SUCCESS;
	}
	
	return SPI_ERROR_CS;
}
static uint32_t SPI2_CsCheck(uint32_t CsPin_number)
{
	uint32_t i;
	
	for(i = 0; i < SPI2_CS_NUMBER; i++)
	{
		if(s2_cs_list[i] == CsPin_number)
			return SPI_OP_SUCCESS;
	}
	
	return SPI_ERROR_CS;
}

/**
 @brief SPI片选信号设置
 @param CsPin_number -[in] 片选引脚
 @param pinState -[in] 引脚状态
 @return 错误代码
*/
static uint32_t SPI0_CsSet(uint32_t CsPin_number , uint8_t pinState)
{
	uint32_t err_code;

	if((err_code = SPI0_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	
	if(pinState == BOARD_SPI_CS_OFF)
	{
		nrf_gpio_pin_write(CsPin_number, 1);
	}
	else if(pinState == BOARD_SPI_CS_ON)
	{
		nrf_gpio_pin_write(CsPin_number, 0);
	}
	
	return SPI_OP_SUCCESS;
}
static uint32_t SPI1_CsSet(uint32_t CsPin_number , uint8_t pinState)
{
	uint32_t err_code;

	if((err_code = SPI1_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	
	if(pinState == BOARD_SPI_CS_OFF)
	{
		nrf_gpio_pin_write(CsPin_number, 1);
	}
	else if(pinState == BOARD_SPI_CS_ON)
	{
		nrf_gpio_pin_write(CsPin_number, 0);
	}
	
	return SPI_OP_SUCCESS;
}
static uint32_t SPI2_CsSet(uint32_t CsPin_number , uint8_t pinState)
{
	uint32_t err_code;

	if((err_code = SPI2_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	
	if(pinState == BOARD_SPI_CS_OFF)
	{
		nrf_gpio_pin_write(CsPin_number, 1);
	}
	else if(pinState == BOARD_SPI_CS_ON)
	{
		nrf_gpio_pin_write(CsPin_number, 0);
	}
	
	return SPI_OP_SUCCESS;
}

/**
 @brief SPI读出写入数据
 @param CsPin_number -[in] 片选引脚
 @param pWriteData -[in] 写入数据
 @param writeDataLen -[in] 写入数据长度
 @param pReadData -[out] 读出数据
 @param readDataLen -[in]	读出数据长度
 @return 错误代码
*/
static uint32_t SPI0_ReadWriteData(uint32_t CsPin_number, uint8_t *pWriteData, uint8_t writeDataLen, uint8_t *pReadData, uint8_t readDataLen)
{
	
	uint32_t err_code;
	uint32_t wait_time_out = WAIT_TIME_VALUE;

	if((err_code = SPI0_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	
	SPI0_CsSet(CsPin_number,BOARD_SPI_CS_ON);						//片选信号开
	
	s0_transferOk = false;
	
	err_code = nrf_drv_spi_transfer(&s0_spiHandle, pWriteData, writeDataLen, pReadData, readDataLen);
	if(err_code != NRF_SUCCESS)return SPI_ERROR_TIMEOUT;

	while(!s0_transferOk)
	{
		if(wait_time_out--){}
		else{
			SPI0_CsSet(CsPin_number,BOARD_SPI_CS_OFF);				//片选信号关
			return SPI_ERROR_TIMEOUT;
		}
	}																											// Error in SPI or transfer already in progress.
	
	SPI0_CsSet(CsPin_number,BOARD_SPI_CS_OFF);						//片选信号关
	return SPI_OP_SUCCESS;
}
static uint32_t SPI1_ReadWriteData(uint32_t CsPin_number, uint8_t *pWriteData, uint8_t writeDataLen, uint8_t *pReadData, uint8_t readDataLen)
{
	
	uint32_t err_code;
	uint32_t wait_time_out = WAIT_TIME_VALUE;

	if((err_code = SPI1_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	
	SPI1_CsSet(CsPin_number,BOARD_SPI_CS_ON);						//片选信号开
	
	s1_transferOk = false;
	
	err_code = nrf_drv_spi_transfer(&s1_spiHandle, pWriteData, writeDataLen, pReadData, readDataLen);
	if(err_code != NRF_SUCCESS)return SPI_ERROR_TIMEOUT;

	while(!s1_transferOk)
	{
		if(wait_time_out--){}
		else{
			SPI1_CsSet(CsPin_number,BOARD_SPI_CS_OFF);				//片选信号关
			return SPI_ERROR_TIMEOUT;
		}
	}																											// Error in SPI or transfer already in progress.
	
	SPI1_CsSet(CsPin_number,BOARD_SPI_CS_OFF);						//片选信号关
	return SPI_OP_SUCCESS;
}
static uint32_t SPI2_ReadWriteData(uint32_t CsPin_number, uint8_t *pWriteData, uint8_t writeDataLen, uint8_t *pReadData, uint8_t readDataLen)
{
	
	uint32_t err_code;
	uint32_t wait_time_out = WAIT_TIME_VALUE;

	if((err_code = SPI2_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	
	SPI2_CsSet(CsPin_number,BOARD_SPI_CS_ON);						//片选信号开
	
	s2_transferOk = false;
	
	err_code = nrf_drv_spi_transfer(&s2_spiHandle, pWriteData, writeDataLen, pReadData, readDataLen);
	if(err_code != NRF_SUCCESS)return SPI_ERROR_TIMEOUT;

	while(!s2_transferOk)
	{
		if(wait_time_out--){}
		else{
			SPI2_CsSet(CsPin_number,BOARD_SPI_CS_OFF);				//片选信号关
			return SPI_ERROR_TIMEOUT;
		}
	}																											// Error in SPI or transfer already in progress.
	
	SPI2_CsSet(CsPin_number,BOARD_SPI_CS_OFF);						//片选信号关
	return SPI_OP_SUCCESS;
}

/**
 @brief SPI读写寄存器数据
 @param CsPin_number -[in] 片选引脚
 @param reg_addr -[in] 操作的寄存器地址
 @param ReadWriteFlag -[in] 读写标志位
 @param pData -[in/out] 指向需要操作的数据
 @param DataLen -[in] 数据长度
 @return 错误代码
*/
static uint8_t  temp_buff[130];
static uint32_t SPI0_ReadWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t ReadWriteFlag, uint8_t *pData, uint8_t DataLen)
{
	
	uint32_t 				err_code;
	uint8_t					addr;
	
	if((err_code = SPI0_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	if(DataLen > (sizeof(temp_buff)-1))return SPI_ERROR_LENGTH;
	if(ReadWriteFlag == SPI_READ)
	{
		addr = 0x80 | reg_addr;
		
		err_code = SPI0_ReadWriteData(CsPin_number, &addr, 1, temp_buff, DataLen+1);	//DataLen+1是因为第一个字节是写地址回应时的垃圾数据
		if(err_code != SPI_OP_SUCCESS) return err_code;
		
		memcpy(pData, &temp_buff[1], DataLen);
	}
	else
	{
		temp_buff[0] = reg_addr;
		memcpy(&temp_buff[1], pData, DataLen);
		
		err_code = SPI0_ReadWriteData(CsPin_number, temp_buff, DataLen+1, NULL, 0);
		if(err_code != SPI_OP_SUCCESS) return err_code;
	}
	
	return SPI_OP_SUCCESS;
}
static uint32_t SPI1_ReadWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t ReadWriteFlag, uint8_t *pData, uint8_t DataLen)
{
	uint32_t 				err_code;
	uint8_t					addr;
	
	if((err_code = SPI1_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	if(DataLen > (sizeof(temp_buff)-1))return SPI_ERROR_LENGTH;
	
	if(ReadWriteFlag == SPI_READ)
	{
		addr = 0x80 | reg_addr;
		
		err_code = SPI1_ReadWriteData(CsPin_number, &addr, 1, temp_buff, DataLen+1);	//DataLen+1是因为第一个字节是写地址回应时的垃圾数据
		if(err_code != SPI_OP_SUCCESS) return err_code;
		memcpy(pData, &temp_buff[1], DataLen);
	}
	else
	{
		temp_buff[0] = reg_addr;
		memcpy(&temp_buff[1], pData, DataLen);
		
		err_code = SPI1_ReadWriteData(CsPin_number, temp_buff, DataLen+1, NULL, 0);
		if(err_code != SPI_OP_SUCCESS) return err_code;
	}
	
	return SPI_OP_SUCCESS;
}
static uint32_t SPI2_ReadWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t ReadWriteFlag, uint8_t *pData, uint8_t DataLen)
{
	uint32_t 				err_code;
	uint8_t					addr;
	
	if((err_code = SPI2_CsCheck(CsPin_number)) != SPI_OP_SUCCESS)return err_code;
	if(DataLen > (sizeof(temp_buff)-1))return SPI_ERROR_LENGTH;
	
	if(ReadWriteFlag == SPI_READ)
	{
		addr = 0x80 | reg_addr;
		
		err_code = SPI2_ReadWriteData(CsPin_number, &addr, 1, temp_buff, DataLen+1);	//DataLen+1是因为第一个字节是写地址回应时的垃圾数据
		if(err_code != SPI_OP_SUCCESS) return err_code;
		
		memcpy(pData, &temp_buff[1], DataLen);
	}
	else
	{
		temp_buff[0] = reg_addr;
		memcpy(&temp_buff[1], pData, DataLen);
		
		err_code = SPI2_ReadWriteData(CsPin_number, temp_buff, DataLen+1, NULL, 0);
		if(err_code != SPI_OP_SUCCESS) return err_code;
	}
	
	return SPI_OP_SUCCESS;
}

static void bsp_spi0_init_process(void)
{
	if(Except_TxError(EXCEPT_SPI_INIT,"bsp_spi0_init_error\r\n") == 0)
	{
		Process_Stop(bsp_spi0_init_process);
	}
}

static void bsp_spi1_init_process(void)
{
	if(Except_TxError(EXCEPT_SPI_INIT,"bsp_spi1_init_error\r\n") == 0)
	{
		Process_Stop(bsp_spi1_init_process);
	}
}

static void bsp_spi2_init_process(void)
{
	if(Except_TxError(EXCEPT_SPI_INIT,"bsp_spi2_init_error\r\n") == 0)
	{
		Process_Stop(bsp_spi2_init_process);
	}
}

/*********************************************************************
 * PUBLIC FUNCTIONS
 */
/****************************************************接口****************************************************/

/**
 @brief SPI的初始化函数
 @param 无
 @return 无
*/
void SPI0_Init(void)
{
	int				 	ret = 0;
	ret_code_t 	errCode;
	
	nrf_drv_spi_config_t spiConfig = NRF_DRV_SPI_DEFAULT_CONFIG;				// 使用SPI默认配置
	// 配置SPI端口，注意CSN不要在这设置，另外用GPIO口控制
	spiConfig.miso_pin = BOARD_SPI0_MISO_IO;
	spiConfig.mosi_pin = BOARD_SPI0_MOSI_IO;
	spiConfig.sck_pin = BOARD_SPI0_CLK_IO;
	spiConfig.mode = NRF_DRV_SPI_MODE_0;
	spiConfig.frequency = SPI0_FREQUENCY;	
	spiConfig.irq_priority = SPI0_IRQ_PRIORITY;													// 在定时器中使用优先级需小于6
	
	errCode = nrf_drv_spi_init(&s0_spiHandle, &spiConfig, spi0CallbackFunc, NULL);
	if(errCode != NRF_SUCCESS)ret = -1;
	
	uint32_t i;
	for(i = 0; i < SPI0_CS_NUMBER; i++)
	{
		nrf_gpio_cfg_output(s0_cs_list[i]);
	}
	
	if(ret == -1)
	{
		Process_Start(0,"spi0_init",bsp_spi0_init_process);
	}
	
}
void SPI1_Init(void)
{
	int				 	ret = 0;
	ret_code_t 	errCode;
	
	nrf_drv_spi_config_t spiConfig = NRF_DRV_SPI_DEFAULT_CONFIG;				// 使用SPI默认配置
	// 配置SPI端口，注意CSN不要在这设置，另外用GPIO口控制
	spiConfig.miso_pin = BOARD_SPI1_MISO_IO;
	spiConfig.mosi_pin = BOARD_SPI1_MOSI_IO;
	spiConfig.sck_pin = BOARD_SPI1_CLK_IO;
	spiConfig.mode = NRF_DRV_SPI_MODE_0;
	spiConfig.frequency = SPI1_FREQUENCY;	
	spiConfig.irq_priority = SPI1_IRQ_PRIORITY;													// 在定时器中使用优先级需小于6
	
	errCode = nrf_drv_spi_init(&s1_spiHandle, &spiConfig, spi1CallbackFunc, NULL);
	if(errCode != NRF_SUCCESS)ret = -1;
	
	uint32_t i;
	for(i = 0; i < SPI1_CS_NUMBER; i++)
	{
		nrf_gpio_cfg_output(s1_cs_list[i]);
	}
	
	if(ret == -1)
	{
		Process_Start(0,"spi1_init",bsp_spi1_init_process);
	}
	
}
void SPI2_Init(void)
{
	int				 	ret = 0;
	ret_code_t 	errCode;
	
	nrf_drv_spi_config_t spiConfig = NRF_DRV_SPI_DEFAULT_CONFIG;				// 使用SPI默认配置
	// 配置SPI端口，注意CSN不要在这设置，另外用GPIO口控制
	spiConfig.miso_pin = BOARD_SPI2_MISO_IO;
	spiConfig.mosi_pin = BOARD_SPI2_MOSI_IO;
	spiConfig.sck_pin = BOARD_SPI2_CLK_IO;
	spiConfig.mode = NRF_DRV_SPI_MODE_0;
	spiConfig.frequency = SPI2_FREQUENCY;	
	spiConfig.irq_priority = SPI2_IRQ_PRIORITY;													// 在定时器中使用优先级需小于6
	
	errCode = nrf_drv_spi_init(&s2_spiHandle, &spiConfig, spi2CallbackFunc, NULL);
	if(errCode != NRF_SUCCESS)ret = -1;
	
	uint32_t i;
	for(i = 0; i < SPI2_CS_NUMBER; i++)
	{
		nrf_gpio_cfg_output(s2_cs_list[i]);
	}
	
	if(ret == -1)
	{
		Process_Start(0,"spi2_init",bsp_spi2_init_process);
	}
	
}

/**
 @brief SPI只读寄存器数据
 @param CsPin_number -[in] 片选引脚
 @param reg_addr -[in] 操作的寄存器地址
 @param pData -[in/out] 指向需要操作的数据
 @param DataLen -[in] 数据长度
 @return 错误代码
*/
uint32_t SPI0_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen)
{
	return SPI0_ReadWriteReg(CsPin_number, reg_addr, SPI_READ, pData, DataLen);
}
uint32_t SPI1_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen)
{
	return SPI1_ReadWriteReg(CsPin_number, reg_addr, SPI_READ, pData, DataLen);
}
uint32_t SPI2_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen)
{
	return SPI2_ReadWriteReg(CsPin_number, reg_addr, SPI_READ, pData, DataLen);
}

/**
 @brief SPI只写寄存器数据
 @param CsPin_number -[in] 片选引脚
 @param reg_addr -[in] 操作的寄存器地址
 @param pData -[in/out] 指向需要操作的数据
 @param DataLen -[in] 数据长度
 @return 错误代码
*/
uint32_t SPI0_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen)
{
	return SPI0_ReadWriteReg(CsPin_number, reg_addr, SPI_WRITE, pData, DataLen);
}
uint32_t SPI1_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen)
{
	return SPI1_ReadWriteReg(CsPin_number, reg_addr, SPI_WRITE, pData, DataLen);
}
uint32_t SPI2_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen)
{
	return SPI2_ReadWriteReg(CsPin_number, reg_addr, SPI_WRITE, pData, DataLen);
}


/**
 @brief 开启SPI
 @param 无
 @return 错误代码
*/
uint32_t SPI0_Enable(void)
{
	SPI0_Init();
	return SPI_OP_SUCCESS;
}
uint32_t SPI1_Enable(void)
{
	SPI1_Init();
	return SPI_OP_SUCCESS;
}
uint32_t SPI2_Enable(void)
{
	SPI2_Init();
	return SPI_OP_SUCCESS;
}

/**
 @brief 禁用SPI
 @param 无
 @return 无
*/
uint32_t SPI0_Disable(void)
{
	
	uint32_t i;
	
	//所有片选信号关
	for(i = 0; i < SPI0_CS_NUMBER; i++)
	{
		SPI0_CsSet(s0_cs_list[i],BOARD_SPI_CS_OFF);		
		nrf_gpio_cfg_default(s0_cs_list[i]);		
	}
	
	
	nrf_drv_spi_uninit(&s0_spiHandle);

	nrf_gpio_cfg_default(BOARD_SPI0_MISO_IO);
	nrf_gpio_cfg_default(BOARD_SPI0_MOSI_IO);
	nrf_gpio_cfg_default(BOARD_SPI0_CLK_IO);
	
	
	
	
	/*I think you're experiencing this increase from this errata since TWI and SPI shares resources internally,
	this errata may also occur when using SPI. Please try this after disabling the SPI:
	
	*(volatile uint32_t *)0x40003FFC = 0;
	*(volatile uint32_t *)0x40003FFC;
	*(volatile uint32_t *)0x40003FFC = 1;

	If SPI1 is used the address is 40004FFC.
	*/
	
	//下面的一调用，所有SPI都会关闭！！！
	
//	*(volatile uint32_t *)0x40003FFC = 0;
//	*(volatile uint32_t *)0x40003FFC;
//	*(volatile uint32_t *)0x40003FFC = 1;
	
	return SPI_OP_SUCCESS;
}
uint32_t SPI1_Disable(void)
{
	
	uint32_t i;
	
	//所有片选信号关
	for(i = 0; i < SPI1_CS_NUMBER; i++)
	{
		SPI1_CsSet(s1_cs_list[i],BOARD_SPI_CS_OFF);		
		nrf_gpio_cfg_default(s1_cs_list[i]);		
	}
	
	
	nrf_drv_spi_uninit(&s1_spiHandle);

	nrf_gpio_cfg_default(BOARD_SPI1_MISO_IO);
	nrf_gpio_cfg_default(BOARD_SPI1_MOSI_IO);
	nrf_gpio_cfg_default(BOARD_SPI1_CLK_IO);
	
	
	
	
	/*I think you're experiencing this increase from this errata since TWI and SPI shares resources internally,
	this errata may also occur when using SPI. Please try this after disabling the SPI:
	
	*(volatile uint32_t *)0x40003FFC = 0;
	*(volatile uint32_t *)0x40003FFC;
	*(volatile uint32_t *)0x40003FFC = 1;

	If SPI1 is used the address is 40004FFC.
	*/
	
		//下面的一调用，所有SPI都会关闭！！！
	
//	*(volatile uint32_t *)0x40003FFC = 0;
//	*(volatile uint32_t *)0x40003FFC;
//	*(volatile uint32_t *)0x40003FFC = 1;
	
	return SPI_OP_SUCCESS;
}
uint32_t SPI2_Disable(void)
{
	
	uint32_t i;
	
	//所有片选信号关
	for(i = 0; i < SPI2_CS_NUMBER; i++)
	{
		SPI2_CsSet(s2_cs_list[i],BOARD_SPI_CS_OFF);		
		nrf_gpio_cfg_default(s2_cs_list[i]);		
	}
	
	
	nrf_drv_spi_uninit(&s2_spiHandle);

	nrf_gpio_cfg_default(BOARD_SPI2_MISO_IO);
	nrf_gpio_cfg_default(BOARD_SPI2_MOSI_IO);
	nrf_gpio_cfg_default(BOARD_SPI2_CLK_IO);
	
	
	
	
	/*I think you're experiencing this increase from this errata since TWI and SPI shares resources internally,
	this errata may also occur when using SPI. Please try this after disabling the SPI:
	
	*(volatile uint32_t *)0x40003FFC = 0;
	*(volatile uint32_t *)0x40003FFC;
	*(volatile uint32_t *)0x40003FFC = 1;

	If SPI1 is used the address is 40004FFC.
	*/
	
		//下面的一调用，所有SPI都会关闭！！！
	
//	*(volatile uint32_t *)0x40003FFC = 0;
//	*(volatile uint32_t *)0x40003FFC;
//	*(volatile uint32_t *)0x40003FFC = 1;
	
	return SPI_OP_SUCCESS;
}





















