高级会员
- 积分
- 685
- 金钱
- 685
- 注册时间
- 2019-4-24
- 在线时间
- 43 小时
|
本帖最后由 高成 于 2019-9-23 18:24 编辑
适用于SX1262的demo程序。
说明:这个是针对8位单片机写的,不过可以简单地移植到任意单片机上(只需要修改与具体平台相关的宏定义)
预览
sx1262.h- #ifndef _SX1262_H_
- #define _SX1262_H_
- #define SoftSPI
- #include "SX1262CommandAndRegs.h"
- #include "main.h"
- #if 0
- typedef unsigned char u8;
- typedef unsigned int u16;
- typedef unsigned long u32;
- #endif
- typedef struct
- {
- u8 Power;
- u32 Frequency;
- u8 Bandwidth;
- u8 SpreadFactor;
- u8 LowDatarateOptimize;
- u8 Coderate;
- u16 PreambleLen;
- u8 HeaderType;
- u8 PayloadLen;
- u8 PacketCrc;
- u8 FreqHopOn;
- u8 HopPeriod;
- u8 IqInverted;
- u8 RxContinuous;
- }RadioLoRaSettings_t;
- #define LED_GREEN p1_1
- #define LED_RED p1_0
- #define SX1262_SPI_NSS_Pin p1_5
- #ifdef SoftSPI
- #define SX1262_SPI_SCK_Pin p1_6
- #define SX1262_SPI_MISO_Pin p4_7
- #define SX1262_SPI_MOSI_Pin p1_4
- #endif // SoftSPI
- #define SX1262_NRST_Pin p1_7
- #define SX1262_DIO1_Pin p1_2
- #define SX1262_DIO2_Pin
- #define SX1262_DIO3_Pin
- #define SX1262_BusyPin p1_3
- #define HIGH 1
- #define LOW 0
- #define SPI_NSS(LEVEL) SX1262_SPI_NSS_Pin=LEVEL
- #ifdef SoftSPI
- #define SPI_SCK(LEVEL) SX1262_SPI_SCK_Pin=LEVEL
- #define SPI_MISO() SX1262_SPI_MISO_Pin
- #define SPI_MOSI(LEVEL) SX1262_SPI_MOSI_Pin=LEVEL
- #endif // SoftSPI
- #define RADIO_NRST(LEVEL) SX1262_NRST_Pin=LEVEL
- #define RADIO_DIO1() SX1262_DIO1_Pin
- #define RADIO_DIO2()
- #define RADIO_DIO3()
- #define RADIO_BusyPin() SX1262_BusyPin
- #define SetRadioPin(pin,state) pin=state
- #define GetRadioPin(pin) pin
- unsigned char spi_byte(unsigned char data);
- u8 SPIWriteCmd(u8 size,u8 *p);
- u8 SPIReadCmd(u8 cmd,u8 *p,u8 size);
- u8 SPIReadRegister(u16 reg,u8 size,u8 *p);
- u8 SPIWriteRegister(u8 *p,u8 size);
- u8 SPIWriteBuffer(u8 offset,u8 *p,u8 size);
- u8 SPIReadBuffer(u8 offset,u8 *p,u8 size);
- void SX1262SetStandby(u8 p);
- void SX1262SetPacketType(u8 p);
- void SX1262SetFrequency(u32 freq);
- void SX1262SetPaConfig(void);
- void SX1262SetTxParams(void);
- void SX1262SetBufferBaseAddress(u8 TXBaseadd,u8 RXBaseadd);
- void SX1262SetModulationParams(u8 sf,u8 bw,u8 codingrate,u8 ldro);
- void SX1262SetPacketParams(u16 prelen,u8 headertype,u8 payloadlen,u8 crc,u8 iq);
- void SX1262SetAnt(void);
- void SX1262SetTCXO_Ctrl(void);
- void SX1262SetDioIrqParams(u16 INT,u16 dio1,u16 dio2,u16 dio3);
- void SX1262Reset(void);
- void port_init(void);
- void SX1262SetRx_mode(u32 timeout);
- void SX1262RX_init(u32 time);
- void SX1262Clr_interrupt(u8 *p);
- void SX1262SetTx_mode(u32 TimeOut);
- void tx_data(u8 add,u8 *p,u8 size);
- void check_busy(void);
- void SX1262GetStatus(u8 *p);
- void SX1262SetRegulatorMode(void);
- void tx11(u8 add ,u8 *p,u8 size);
- u8 SX1262GetReceiveLen(void);
- u8 SX1262GetReceiveAdd(void);
- int SX1262Init(RadioLoRaSettings_t LoRaSetting);
- int RadioInit(void);
- /*****extern variables****************/
- extern RadioLoRaSettings_t LoRaSetting1;
- #endif // _SX1262_H_
|
|