bsp_spi.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_FRONT_SPI_MISO // SPI0主输入从输出IO口
  20. #define BOARD_SPI0_MOSI_IO PIN_FRONT_SPI_MOSI // SPI0主输出从输入IO口
  21. #define BOARD_SPI0_CLK_IO PIN_FRONT_SPI_SCLK // SPI0时钟控制IO口
  22. #define SPI0_CS_NUMBER 1 // SPI0片选引脚数量
  23. #define BOARD_SPI0_CS0_IO PIN_FRONT_SPI_nCS // SPI0片选0信号IO口
  24. #define SPI0_CS_LIST {BOARD_SPI0_CS0_IO} // SPI0片选引脚列表
  25. #define BOARD_SPI1_MISO_IO PIN_FLASH_SPI_MISO // SPI1主输入从输出IO口
  26. #define BOARD_SPI1_MOSI_IO PIN_FLASH_SPI_MOSI // SPI1主输出从输入IO口
  27. #define BOARD_SPI1_CLK_IO PIN_FLASH_SPI_SCLK // SPI1时钟控制IO口
  28. #define SPI1_CS_NUMBER 1 // SPI1片选引脚数量
  29. #define BOARD_SPI1_CS0_IO PIN_FLASH_SPI_nCS // SPI1片选0信号IO口
  30. #define SPI1_CS_LIST {BOARD_SPI1_CS0_IO} // SPI1片选引脚列表
  31. #define BOARD_SPI2_MISO_IO 0xFF // SPI2主输入从输出IO口
  32. #define BOARD_SPI2_MOSI_IO 0xFF // SPI2主输出从输入IO口
  33. #define BOARD_SPI2_CLK_IO 0xFF // SPI2时钟控制IO口
  34. #define SPI2_CS_NUMBER 1 // SPI2片选引脚数量
  35. #define BOARD_SPI2_CS0_IO 0xFF // SPI2片选0信号IO口
  36. #define SPI2_CS_LIST {BOARD_SPI2_CS0_IO} // SPI2片选引脚列表
  37. #define SPI_INSTANCE_0 0 // SPI0 instance index
  38. #define SPI_INSTANCE_1 1 // SPI1 instance index
  39. #define SPI_INSTANCE_2 2 // SPI2 instance index
  40. #define SPI0_FREQUENCY NRF_DRV_SPI_FREQ_8M // SPI0 频率
  41. #define SPI1_FREQUENCY NRF_DRV_SPI_FREQ_8M // SPI1 频率
  42. #define SPI2_FREQUENCY NRF_DRV_SPI_FREQ_8M // SPI2 频率
  43. #define WAIT_TIME_VALUE 10000 // 等待超时最大值 - 1ms 8M-145临界值
  44. #define SPI_READ 0x00 //读标志位
  45. #define SPI_WRITE 0x01 //写标志位
  46. //ERROR CODE
  47. #define SPI_OP_SUCCESS 0x00 // spi操作成功
  48. #define SPI_ERROR_TIMEOUT (SPI_OP_SUCCESS+0x01) // 超时错误
  49. #define SPI_ERROR_CS (SPI_OP_SUCCESS+0x02) // 片选引脚错误
  50. #define SPI_ERROR_LENGTH (SPI_OP_SUCCESS+0x03) // 数据长度太长
  51. /*********************************************************************
  52. * API FUNCTIONS
  53. */
  54. //SPI0初始化
  55. void SPI0_Init(void);
  56. //SPI0只读寄存器数据
  57. uint32_t SPI0_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  58. //SPI0只写寄存器数据
  59. uint32_t SPI0_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  60. //开启SPI0
  61. uint32_t SPI0_Enable(void);
  62. //禁用SPI0,实现低功耗配合SPI_Enable使用
  63. uint32_t SPI0_Disable(void);
  64. //SPI1初始化
  65. void SPI1_Init(void);
  66. //SPI1只读寄存器数据
  67. uint32_t SPI1_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  68. //SPI1只写寄存器数据
  69. uint32_t SPI1_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  70. //开启SPI1
  71. uint32_t SPI1_Enable(void);
  72. //禁用SPI1,实现低功耗配合SPI_Enable使用
  73. uint32_t SPI1_Disable(void);
  74. //SPI2初始化
  75. void SPI2_Init(void);
  76. //SPI2只读寄存器数据
  77. uint32_t SPI2_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  78. //SPI2只写寄存器数据
  79. uint32_t SPI2_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  80. //开启SPI2
  81. uint32_t SPI2_Enable(void);
  82. //禁用SPI2,实现低功耗配合SPI_Enable使用
  83. uint32_t SPI2_Disable(void);
  84. #endif /* _BOARD_SPI_H_ */