高级会员
- 积分
- 685
- 金钱
- 685
- 注册时间
- 2019-4-24
- 在线时间
- 43 小时
|
本帖最后由 高成 于 2019-9-26 14:50 编辑
主控是瑞萨R8C R5F211B4,8位单片机。不过可以轻松移植到任意单片机上。因为在sx1276的c文件里面我把与具体单片机的IO控制语句都写成了宏定义的形式,移植的时候只需要修改端口操作的宏定义。
工程文件可以用High-performance Embedded Workshop打开
sx1276.h文件预览:
- #ifndef _SX127X_H_
- #define _SX127X_H_
- #include "stdbool.h"
- #include "sx1276Regs-LoRa.h"
- // IO 定义(软件模拟SPI)
- #define LED_TX p1_0 // 输出,发射指示灯
- #define LED_RX p1_1 // 输出,接收指示灯
- #define MOSI p1_4 // 输出,SPI MOSI
- #define nCS p1_5 // 输出, SPI使能脚
- #define SCK p1_6 // 输出,SPI时钟
- #define RF_RST p1_7 // 输出,SX1276复位脚
- #define rx_en p3_7 // 输出,天线开关控制,接收状态时为高
- #define tx_en p4_5 // 输出,天线开关控制,发射状态时为高
- #define MISO p4_7 // 输入,SPI MISO
- #define SX127X_NRST p1_7
- #define SX127X_SPI_NSS p1_5
- #define SX127X_SPI_CLK p1_6
- #define SX127X_SPI_MISO p4_7
- #define SX127X_SPI_MOSI p1_4
- #define SX127X_TX_EN p4_5
- #define SX127X_RX_EN p3_7
- #define HIGH 1
- #define LOW 0
- #define RADIO_NRST(LEVEL) SX127X_NRST=LEVEL//HAL_GPIO_WritePin(GPIOB,SX127X_SPI_NRST,LEVEL)
- #define SPI_NSS(LEVEL) SX127X_SPI_NSS=LEVEL//HAL_GPIO_WritePin(GPIOA,SX127X_SPI_NSS,LEVEL)
- #define SPI_CLK(LEVEL) SX127X_SPI_CLK=LEVEL//HAL_GPIO_WritePin(GPIOA,SX127X_SPI_CLK,LEVEL)
- #define SPI_MOSI(LEVEL) SX127X_SPI_MOSI=LEVEL//HAL_GPIO_WritePin(GPIOA,SX127X_SPI_MOSI,LEVEL)
- #define SPI_MISO() SX127X_SPI_MISO// SX12HAL_GPIO_ReadPin(GPIOA,SX127X_SPI_MISO)
- #define RADIO_TX_EN(LEVEL) SX127X_TX_EN=LEVEL//HAL_GPIO_WritePin(GPIOA,SX127X_TX_EN,LEVEL)
- #define RADIO_RX_EN(LEVEL) SX127X_RX_EN=LEVEL//HAL_GPIO_WritePin(GPIOA,SX127X_RX_EN,LEVEL)
- typedef enum
- {
- Power_defaulr=0x84,
- Power_high=0x87,
- }PaDacTypedef;
- typedef enum
- {
- CLOCK_Crystal_Oscillator=0x00,
- CLOCK_TCXO=0x10,
- }RFClockTypedef;
- /*
- typedef struct
- {
- unsigned long Frequency;
- unsigned char PreambleLen;
- unsigned char PayloadLen;
- unsigned char Spreadfactor;
- unsigned char Bandwidth;
- unsigned char CRCon;
- unsigned char LowDatarateOpt;
- }RadioLoRaSettings_t;
- */
- /*!
- * Radio LoRa modem parameters
- */
- typedef struct
- {
- unsigned char Power;
- unsigned long Frequency;
- unsigned char Bandwidth;
- unsigned char SpreadFactor;
- bool LowDatarateOptimize;
- unsigned char Coderate;
- unsigned int PreambleLen;
- bool FixLen;
- unsigned char PayloadLen;
- bool CrcOn;
- bool FreqHopOn;
- unsigned char HopPeriod;
- bool IqInverted;
- bool RxContinuous;
- unsigned char TxTimeout;
- }RadioLoRaSettings_t;
- extern RadioLoRaSettings_t LoraSetting1;
- unsigned char SpiInOut(unsigned char data);
- unsigned char SPIReadReg(unsigned char addr);
- void SPIWriteReg(unsigned char addr, unsigned char value);
- void SPIBurstRead(unsigned char addr, unsigned char *ptr, unsigned char len);
- void SPIBurstWrite(unsigned char addr, unsigned char *ptr, unsigned char len);
- void SX1276SetChannel( unsigned long freq );
- void SX1276Reset( void );
- void SX1276SetOpMode( unsigned char opMode );
- void SX1276SetSleep( void );
- void SX1276SetStby( void );
- void SX1276SetOutPower(unsigned char power);
- void SX1276SetOcp(unsigned char ocp);
- void SX1276SetLNA(unsigned char lna);
- void SX1276SetLoraSpreadingFactor(unsigned char SpreadFactor);
- void SX1276SetLoRaBandwidth(unsigned char bw);
- void SX1276SetLoRaCodingRate(unsigned char codingrate);
- void SX1276SetLoRaHeaderMode(bool headermode);
- void SX1276SetCRC(bool crc);
- void SX1276SetLowDataRateOptimize(bool on);
- void SX1276SetSymbTimeout(unsigned int timeout);
- void SX1276SetPacketParameters(unsigned int PremebleLen,unsigned char payloadlen,unsigned char PayloadMaxLength);
- void SX1276SetPayloadLen(unsigned char len);
- void SX1276SetHopPeriod(unsigned char hopperiod);
- void SX1276SetPA(unsigned char paconfig,PaDacTypedef pa);
- unsigned char SX1276ReadRssi( unsigned long Frequency);
- void SX1276SetIRQ(unsigned char irq );
- void SX1276SetDIO(unsigned int dio);
- unsigned long SX1276GetTimeOnAir( RadioLoRaSettings_t LoraSetting);
- void SX1276ClearIRQ(void);
- void SX1276SetTCXO(RFClockTypedef temp);
- void SX1276SetMode(unsigned char mode);
- void SX1276_Init(RadioLoRaSettings_t LoraSetting);
- void SX1276SetRx(void);
- void SX176SetTx(RadioLoRaSettings_t LoraSetting,unsigned char *p,unsigned char len);
- void port_init(void);
- #endif // _SX127X_H_
|
|