123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #ifndef __BSP_SPI_H__
- #define __BSP_SPI_H__
- //SPI 1.0V
- /*********************************************************************
- * INCLUDES
- */
- #include "nrf_drv_spi.h"
- #include "nrf_gpio.h"
- #include "nrf_pwr_mgmt.h"
- #include <string.h>
- #include "app_error.h"
- #include "SEGGER_RTT.h"
- #include "usr_config.h"
- /*********************************************************************
- * DEFINITIONS
- */
- #define BOARD_SPI_CS_ON 0 // SPI片选信号开
- #define BOARD_SPI_CS_OFF 1 // SPI片选信号关
- #define BOARD_SPI0_MISO_IO PIN_FRONT_SPI_MISO // SPI0主输入从输出IO口
- #define BOARD_SPI0_MOSI_IO PIN_FRONT_SPI_MOSI // SPI0主输出从输入IO口
- #define BOARD_SPI0_CLK_IO PIN_FRONT_SPI_SCLK // SPI0时钟控制IO口
- #define SPI0_CS_NUMBER 1 // SPI0片选引脚数量
- #define BOARD_SPI0_CS0_IO PIN_FRONT_SPI_nCS // SPI0片选0信号IO口
- #define SPI0_CS_LIST {BOARD_SPI0_CS0_IO} // SPI0片选引脚列表
- #define BOARD_SPI1_MISO_IO PIN_FLASH_SPI_MISO // SPI1主输入从输出IO口
- #define BOARD_SPI1_MOSI_IO PIN_FLASH_SPI_MOSI // SPI1主输出从输入IO口
- #define BOARD_SPI1_CLK_IO PIN_FLASH_SPI_SCLK // SPI1时钟控制IO口
- #define SPI1_CS_NUMBER 1 // SPI1片选引脚数量
- #define BOARD_SPI1_CS0_IO PIN_FLASH_SPI_nCS // SPI1片选0信号IO口
- #define SPI1_CS_LIST {BOARD_SPI1_CS0_IO} // SPI1片选引脚列表
- #define BOARD_SPI2_MISO_IO 0xFF // SPI2主输入从输出IO口
- #define BOARD_SPI2_MOSI_IO 0xFF // SPI2主输出从输入IO口
- #define BOARD_SPI2_CLK_IO 0xFF // SPI2时钟控制IO口
- #define SPI2_CS_NUMBER 1 // SPI2片选引脚数量
- #define BOARD_SPI2_CS0_IO 0xFF // SPI2片选0信号IO口
- #define SPI2_CS_LIST {BOARD_SPI2_CS0_IO} // SPI2片选引脚列表
- #define SPI_INSTANCE_0 0 // SPI0 instance index
- #define SPI_INSTANCE_1 1 // SPI1 instance index
- #define SPI_INSTANCE_2 2 // SPI2 instance index
- #define SPI0_FREQUENCY NRF_DRV_SPI_FREQ_8M // SPI0 频率
- #define SPI1_FREQUENCY NRF_DRV_SPI_FREQ_8M // SPI1 频率
- #define SPI2_FREQUENCY NRF_DRV_SPI_FREQ_8M // SPI2 频率
- #define WAIT_TIME_VALUE 10000 // 等待超时最大值 - 1ms 8M-145临界值
- #define SPI_READ 0x00 //读标志位
- #define SPI_WRITE 0x01 //写标志位
- //ERROR CODE
- #define SPI_OP_SUCCESS 0x00 // spi操作成功
- #define SPI_ERROR_TIMEOUT (SPI_OP_SUCCESS+0x01) // 超时错误
- #define SPI_ERROR_CS (SPI_OP_SUCCESS+0x02) // 片选引脚错误
- #define SPI_ERROR_LENGTH (SPI_OP_SUCCESS+0x03) // 数据长度太长
- /*********************************************************************
- * API FUNCTIONS
- */
-
- //SPI0初始化
- void SPI0_Init(void);
- //SPI0只读寄存器数据
- uint32_t SPI0_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
- //SPI0只写寄存器数据
- uint32_t SPI0_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
- //开启SPI0
- uint32_t SPI0_Enable(void);
- //禁用SPI0,实现低功耗配合SPI_Enable使用
- uint32_t SPI0_Disable(void);
- //SPI1初始化
- void SPI1_Init(void);
- //SPI1只读寄存器数据
- uint32_t SPI1_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
- //SPI1只写寄存器数据
- uint32_t SPI1_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
- //开启SPI1
- uint32_t SPI1_Enable(void);
- //禁用SPI1,实现低功耗配合SPI_Enable使用
- uint32_t SPI1_Disable(void);
- //SPI2初始化
- void SPI2_Init(void);
- //SPI2只读寄存器数据
- uint32_t SPI2_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
- //SPI2只写寄存器数据
- uint32_t SPI2_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
- //开启SPI2
- uint32_t SPI2_Enable(void);
- //禁用SPI2,实现低功耗配合SPI_Enable使用
- uint32_t SPI2_Disable(void);
- #endif /* _BOARD_SPI_H_ */
|