bsp_spi.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef __BSP_SPI_H__
  2. #define __BSP_SPI_H__
  3. //SPI 1.0V
  4. /*********************************************************************
  5. * INCLUDES
  6. */
  7. #include "nrf_drv_spi.h"
  8. #include "nrf_gpio.h"
  9. #include "nrf_pwr_mgmt.h"
  10. #include <string.h>
  11. #include "app_error.h"
  12. #include "SEGGER_RTT.h"
  13. #include "usr_config.h"
  14. /*********************************************************************
  15. * DEFINITIONS
  16. */
  17. #define BOARD_SPI_CS_ON 0 // SPI片选信号开
  18. #define BOARD_SPI_CS_OFF 1 // SPI片选信号关
  19. #define BOARD_SPI0_MISO_IO PIN_LSM_MISO // SPI主输入从输出IO口
  20. #define BOARD_SPI0_MOSI_IO PIN_LSM_MOSI // SPI主输出从输入IO口
  21. #define BOARD_SPI0_CLK_IO PIN_LSM_SCLK // SPI时钟控制IO口
  22. #define SPI_CS_NUMBER 1 // SPI片选引脚数量
  23. #define BOARD_SPI0_CS0_IO PIN_LSM_nCS // SPI片选0信号IO口
  24. #define SPI_CS_LIST {BOARD_SPI0_CS0_IO} // SPI片选引脚列表
  25. #define SPI_INSTANCE 0 // SPI instance index
  26. #define SPI_FREQUENCY NRF_DRV_SPI_FREQ_8M // SPI 频率
  27. #define WAIT_TIME_VALUE 3 // 等待超时最大值
  28. #define SPI_READ 0x00 //读标志位
  29. #define SPI_WRITE 0x01 //写标志位
  30. //ERROR CODE
  31. #define SPI_OP_SUCCESS 0x00 // spi操作成功
  32. #define SPI_ERROR_TIMEOUT (SPI_OP_SUCCESS+0x01) // 超时错误
  33. #define SPI_ERROR_CS (SPI_OP_SUCCESS+0x02) // 片选引脚错误
  34. /*********************************************************************
  35. * API FUNCTIONS
  36. */
  37. //SPI初始化
  38. void SPI_Init(void);
  39. //SPI只读寄存器数据
  40. uint32_t SPI_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  41. //SPI只写寄存器数据
  42. uint32_t SPI_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  43. //开启SPI
  44. uint32_t SPI_Enable(void);
  45. //禁用SPI,实现低功耗配合SPI_Enable使用
  46. uint32_t SPI_Disable(void);
  47. #endif /* _BOARD_SPI_H_ */