48 SX1272_writeRegister(lora, SX1272_REG_OP_MODE,
49 0x01 << SX1272_OP_MODE_LONG_RANGE_Pos
52 SX1272_writeRegister(lora, SX1272_REG_MODEM_CONFIG1,
53 bw << SX1272_REG_MODEM_CONFIG1_BW_Pos
54 | cr << SX1272_REG_MODEM_CONFIG1_CR_Pos
55 | 0x00 << SX1272_REG_MODEM_CONFIG1_CRC_Pos
62 SX1272_writeRegister(lora, SX1272_REG_MODEM_CONFIG2, 0x94);
65 SX1272_writeRegister(lora, SX1272_REG_PAYLOAD_LENGTH, LORA_MSG_LENGTH);
66 SX1272_writeRegister(lora, SX1272_REG_MAX_PAYLOAD_LENGTH, LORA_MSG_LENGTH);
71 SX1272_writeRegister(lora, SX1272_REG_FIFO_TX_BASE_ADDR, 0x00);
72 SX1272_writeRegister(lora, SX1272_REG_FIFO_RX_BASE_ADDR, 0x00);
80#ifndef DOXYGEN_PRIVATE
94 uint8_t regOpMode = SX1272_readRegister(lora, SX1272_REG_OP_MODE);
97 SX1272_writeRegister(lora, SX1272_REG_OP_MODE, regOpMode);
115 uint8_t regPaConfig = SX1272_readRegister(lora, SX1272_REG_PA_CONFIG);
116 regPaConfig &= ~SX1272_PA_SELECT;
117 SX1272_writeRegister(lora, SX1272_REG_PA_CONFIG, regPaConfig | SX1272_PA_SELECT);
148 SX1272_writeRegister(lora, SX1272_REG_DIO_MAPPING1, SX1272_LORA_DIO_TXDONE);
161 SX1272_writeRegister(lora, SX1272_REG_IRQ_FLAGS, SX1272_LORA_IRQ_TXDONE);
162 SX1272_writeRegister(lora, SX1272_REG_FIFO_ADDR_PTR, 0x00);
165 for (
int i = 0; i < 32; i++) {
166 SX1272_writeRegister(lora, SX1272_REG_FIFO, pointerdata[i]);
188 SX1272_writeRegister(lora, SX1272_REG_DIO_MAPPING1, SX1272_LORA_DIO_RXDONE);
201 SX1272_writeRegister(lora, SX1272_REG_IRQ_FLAGS, SX1272_LORA_IRQ_RXDONE);
202 SX1272_writeRegister(lora, SX1272_REG_FIFO_ADDR_PTR, 0x00);
231 SX1272_writeRegister(lora, SX1272_REG_IRQ_FLAGS, SX1272_LORA_IRQ_RXDONE);
234 uint8_t bytesReceived = SX1272_readRegister(lora, SX1272_REG_RX_BYTES);
235 uint8_t rxCurrentAddr = SX1272_readRegister(lora, SX1272_REG_FIFO_RX_CURR_ADDR);
238 if (bytesReceived > buffSize)
242 SX1272_writeRegister(lora, SX1272_REG_FIFO_ADDR_PTR, rxCurrentAddr);
243 for (
int i = 0; i < bytesReceived; i++) {
244 buffer[i] = SX1272_readRegister(lora, SX1272_REG_FIFO);
262 SX1272_writeRegister(lora, SX1272_REG_IRQ_FLAGS, flags);
267void SX1272_writeRegister(
SX1272_t *lora, uint8_t address, uint8_t data) {
275 uint8_t payload = address | 0x80;
283uint8_t SX1272_readRegister(
SX1272_t *lora, uint8_t address) {
284 uint8_t response = 0;
292 uint8_t payload = address & 0x7F;
293 response = spi->
transmit(spi, payload);
294 response = spi->
transmit(spi, 0xFF);
void(* set)(struct GPIOpin *)
void(* reset)(struct GPIOpin *)
Struct definition for a GPIO pin.
uint16_t(* transmit)(struct SPI *, uint16_t)
SPI transmit method.
Struct definition for SPI interface. Provides the interface for API consumers to interact with the SP...
void(* enableBoost)(struct SX1272 *, bool)
Power amp boost toggle method.
void(* standby)(struct SX1272 *)
SX1272 standby method.
void(* startReceive)(struct SX1272 *)
SX1272 LoRa continuous receive method.
bool(* readReceive)(struct SX1272 *, uint8_t *, uint8_t)
SX1272 LoRa receive buffer read method.
GPIOpin_t cs
Chip select GPIO.
void(* transmit)(struct SX1272 *, uint8_t *)
SX1272 LoRa transmit method.
SPI_t * base
Parent SPI interface.
void(* clearIRQ)(struct SX1272 *, uint8_t)
SX1272 LoRa IRQ flag clear method.
SX1272_Mode currentMode
Current operating mode.
void SX1272_transmit(SX1272_t *, uint8_t *)
Transmits data using the SX1272.
SX1272_Bandwidth
SX1272 bandwidth enum.
void _SX1272_setMode(SX1272_t *lora, SX1272_Mode mode)
Sets the operational mode of the LoRa module.
bool SX1272_readReceive(SX1272_t *, uint8_t *, uint8_t)
Reads contents of received packet to local buffer from the SX1272.
SX1272_SpreadingFactor
SX1272 spreading factor enum.
SX1272_Mode
SX1272 operating mode enum.
void SX1272_standby(SX1272_t *)
Sets the operational mode of the LoRa module to standby.
SX1272_t SX1272_init(SX1272_t *lora, SPI_t *spi, GPIOpin_t cs, SX1272_Bandwidth bw, SX1272_SpreadingFactor sf, SX1272_CodingRate cr)
Initializes the LoRa module with specified configuration parameters.
SX1272_CodingRate
SX1272 coding rate enum.
void SX1272_startReceive(SX1272_t *)
Begins continuous receive on the SX1272.
void SX1272_enableBoost(SX1272_t *, bool)
Enables/disables power amplifier boost.
void SX1272_clearIRQ(SX1272_t *, uint8_t)
Sets the value of RegIrqFlags in the SX1272 to the provided argument value. Writing a 1 to a bit in t...
Struct definition for SX1272. Provides the interface for API consumers to interact with the SX1272 Lo...