bsp_spi.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_CENTER_SPI_MISO // SPI1主输入从输出IO口
  26. #define BOARD_SPI1_MOSI_IO PIN_CENTER_SPI_MOSI // SPI1主输出从输入IO口
  27. #define BOARD_SPI1_CLK_IO PIN_CENTER_SPI_SCLK // SPI1时钟控制IO口
  28. #define SPI1_CS_NUMBER 1 // SPI1片选引脚数量
  29. #define BOARD_SPI1_CS0_IO PIN_CENTER_SPI_nCS // SPI1片选0信号IO口
  30. #define SPI1_CS_LIST {BOARD_SPI1_CS0_IO} // SPI1片选引脚列表
  31. #define BOARD_SPI2_MISO_IO PIN_BACK_SPI_MISO // SPI2主输入从输出IO口
  32. #define BOARD_SPI2_MOSI_IO PIN_BACK_SPI_MOSI // SPI2主输出从输入IO口
  33. #define BOARD_SPI2_CLK_IO PIN_BACK_SPI_SCLK // SPI2时钟控制IO口
  34. #define SPI2_CS_NUMBER 1 // SPI2片选引脚数量
  35. #define BOARD_SPI2_CS0_IO PIN_BACK_SPI_nCS // 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 3 // 等待超时最大值
  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. /*********************************************************************
  51. * API FUNCTIONS
  52. */
  53. //SPI0初始化
  54. void SPI0_Init(void);
  55. //SPI0只读寄存器数据
  56. uint32_t SPI0_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  57. //SPI0只写寄存器数据
  58. uint32_t SPI0_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  59. //开启SPI0
  60. uint32_t SPI0_Enable(void);
  61. //禁用SPI0,实现低功耗配合SPI_Enable使用
  62. uint32_t SPI0_Disable(void);
  63. //SPI1初始化
  64. void SPI1_Init(void);
  65. //SPI1只读寄存器数据
  66. uint32_t SPI1_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  67. //SPI1只写寄存器数据
  68. uint32_t SPI1_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  69. //开启SPI1
  70. uint32_t SPI1_Enable(void);
  71. //禁用SPI1,实现低功耗配合SPI_Enable使用
  72. uint32_t SPI1_Disable(void);
  73. //SPI2初始化
  74. void SPI2_Init(void);
  75. //SPI2只读寄存器数据
  76. uint32_t SPI2_OnlyReadReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  77. //SPI2只写寄存器数据
  78. uint32_t SPI2_OnlyWriteReg(uint32_t CsPin_number, uint8_t reg_addr, uint8_t *pData, uint8_t DataLen);
  79. //开启SPI2
  80. uint32_t SPI2_Enable(void);
  81. //禁用SPI2,实现低功耗配合SPI_Enable使用
  82. uint32_t SPI2_Disable(void);
  83. #endif /* _BOARD_SPI_H_ */