sx1278_ports.c
1278接口连接
使用两个关键字来定义接口:端口和编号,如(GPIOD,GPIO_Pin_6)
DIO接口
#define DIO0_IOPORT GPIOD
#define DIO0_PIN GPIO_Pin_6
#define DIO0_EXTI EXTI_Pin_6
#define DIO1_IOPORT GPIOD
#define DIO1_PIN GPIO_Pin_5
#define DIO2_IOPORT GPIOD
#define DIO2_PIN GPIO_Pin_4
#define DIO3_IOPORT GPIOB
#define DIO3_PIN GPIO_Pin_2
#define DIO4_IOPORT GPIOB
#define DIO4_PIN GPIO_Pin_1
#define DIO5_IOPORT GPIOB
#define DIO5_PIN GPIO_Pin_0
DIO0——D6
DIO1——D5
DIO2——D4
DIO3——B2
DIO4——B1
DIO5——B0
复位口
/* SX1278 NRESET pin connect to PC0 */
#define LORA_RST_IOPORT GPIOC
#define LORA_RST_PIN GPIO_Pin_0
RST——C0
电源模式口
/* 0=set RF to low power by turn off OCO, 1=set RF to run mode by turn on OCO */
#define LORA_IOVCC_PORT GPIOF
#define LORA_IOVCC_PIN GPIO_Pin_0
F0
置0:通过关闭oco使RF进入低电量模式(OCO是啥?)
置1:通过开启oco使RF进入运行模式
发送/接收口
/* RF_TX: RXE=0, TXE=1; RF_RX: RXE=1, TXE=0 */
#define LORA_RXE_PORT GPIOE
#define LORA_RXE_PIN GPIO_Pin_2
#define LORA_TXE_PORT GPIOD
#define LORA_TXE_PIN GPIO_Pin_7
RXE——E2;
TXE——D7;
PC-STM8串口通信帧格式:
/**
* @brief Type of received communication frame
*/
typedef enum
{
TYPE_INVALID_MIN = (uint8_t)0,
TYPE_GET_VER = (uint8_t)1, /*!< User System get version of this node. */
TYPE_TX_RF_DATA = (uint8_t)2, /*!< User System send data that need to TX by RF. */
TYPE_SET_RF_SETTINGS = (uint8_t)3, /*!< User System set settings of RF. */
TYPE_GET_RF_SETTINGS = (uint8_t)4, /*!< User System get settings of RF. */
TYPE_SET_TX_PWR = (uint8_t)7, /*!< User System set TX power of RF. */
TYPE_GET_TX_PWR = (uint8_t)8, /*!< User System get TX power of RF. */
TYPE_GET_PKT_RSSI = (uint8_t)0x0A, /*!< User System get the RSSI of the latest packet received. */
TYPE_INVALID_MAX,
TYPE_WAKE_DATA = ((uint8_t)0xC0), /*!< Node send wake data to User System. */
} COMM_FRAME_TYPE_TypeDef;
/* Exported variables ------------------------------------------------------- */
typedef struct
{
uint8_t byHead;
COMM_FRAME_TYPE_TypeDef eType;
uint8_t byDataSize;
} COMM_FRAME_HEAD;
typedef struct
{
uint8_t byCS;
uint8_t byTail;
} COMM_FRAME_TAIL;
STM8 LoRa接口
/* Exported functions ------------------------------------------------------- */
void SX1278Init(const RadioEvents_t *p_stEvents);
RadioState_t SX1278GetStatus(void);
bool SX1278IsChannelFree(uint16_t wPeriodMs, int16_t nRssiThresh);
bool SX1278IsReceiving(uint16_t wPeriodMs);
void SX1278SetFreq(uint32_t freq);
void SX1278SetPAOutput(PA_OUTPUT_PIN_TypeDef ePAOutput);
void SX1278SetTxPower(int8_t chPower);
/**
* @brief Write the changed settings into registers of LoRa.
* @note MUST call this function after changed settings of LoRa.
*/
void SX1278SetLoRaSettings(void);
void SX1278SetPreambleLen(uint16_t wLen);
void SX1278SetBandwidth(RadioBW_t tBW);
void SX1278SetSpreadingFactor(RadioSF_t tSF);
void SX1278SetCodingRate(RadioFEC_t tFEC);
void SX1278SetLowDatarateOptimize(bool bOptimize);
void SX1278SetFixLen(bool bFixLen);
void SX1278SetCrcOn(bool bCrcOn);
void SX1278SetRxContinuous(bool bRxContinuous);
void SX1278SetTxTimeout(uint16_t wTxTimeout);
uint16_t SX1278GetTimeOnAir(uint8_t byPayload);
uint16_t SX1278GetPreambleTime(void);
int16_t SX1278CalcPreambleNum(uint16_t wMs);
uint16_t SX1278CalcPreambleNumExt(uint16_t wMs, RadioBW_t tBW, RadioSF_t tSF);
void SX1278SetSleep(void);
void SX1278SetStandby(void);
int8_t SX1278PrepareTx(const uint8_t *p_byBuf, uint8_t bySize);
void SX1278Transmit(void);
int8_t SX1278Send(const void *p_vBuf, uint8_t bySize);
int8_t SX1278Receive(uint16_t wTimeout);
int8_t SX1278SetCAD(uint16_t wTimeout);
uint8_t SX1278Read(uint8_t addr);