[SX123x] Added support for SX1233 (#898)

pull/914/head
jgromes 2023-12-09 15:34:56 +01:00
rodzic 77562c963a
commit c0d8d7871e
9 zmienionych plików z 199 dodań i 12 usunięć

Wyświetl plik

@ -25,7 +25,7 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github
* __SX126x__ series LoRa modules (SX1261, SX1262, SX1268)
* __SX127x__ series LoRa modules (SX1272, SX1273, SX1276, SX1277, SX1278, SX1279)
* __SX128x__ series LoRa/GFSK/BLE/FLRC modules (SX1280, SX1281, SX1282)
* __SX1231__ FSK/OOK radio module
* __SX123x__ FSK/OOK radio modules (SX1231, SX1233)
### Supported protocols and digital modes:
* [__AX.25__](https://www.sigidwiki.com/wiki/PACKET) using 2-FSK or AFSK for modules:

Wyświetl plik

@ -1,9 +1,10 @@
/*
RadioLib SX1231 Blocking Receive Example
RadioLib SX123x Blocking Receive Example
This example receives packets using SX1231 FSK radio module.
Other modules from SX123x family can also be used.
NOTE: SX1231 offers the same features as RF69 and has the same
NOTE: SX123x modules offer the same features as RF69 and have the same
interface. Please see RF69 examples for examples on AES,
address filtering, interrupts and settings.

Wyświetl plik

@ -1,9 +1,10 @@
/*
RadioLib SX1231 Blocking Transmit Example
RadioLib SX123x Blocking Transmit Example
This example transmits packets using SX1231 FSK radio module.
Other modules from SX123x family can also be used.
NOTE: SX1231 offers the same features as RF69 and has the same
NOTE: SX123x modules offer the same features as RF69 and have the same
interface. Please see RF69 examples for examples on AES,
address filtering, interrupts and settings.

Wyświetl plik

@ -28,6 +28,7 @@ Si4431 KEYWORD1
Si4432 KEYWORD1
SIM800 KEYWORD1
SX1231 KEYWORD1
SX1233 KEYWORD1
SX1261 KEYWORD1
SX1262 KEYWORD1
SX1268 KEYWORD1

Wyświetl plik

@ -84,7 +84,8 @@
#include "modules/Si443x/Si4430.h"
#include "modules/Si443x/Si4431.h"
#include "modules/Si443x/Si4432.h"
#include "modules/SX1231/SX1231.h"
#include "modules/SX123x/SX1231.h"
#include "modules/SX123x/SX1233.h"
#include "modules/SX126x/SX1261.h"
#include "modules/SX126x/SX1262.h"
#include "modules/SX126x/SX1268.h"

Wyświetl plik

@ -16,7 +16,7 @@ int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t po
bool flagFound = false;
while((i < 10) && !flagFound) {
int16_t version = getChipVersion();
if((version == 0x21) || (version == 0x22) || (version == 0x23)) {
if((version == RADIOLIB_SX123X_CHIP_REVISION_2_A) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_B) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_C)) {
flagFound = true;
this->chipRevision = version;
} else {
@ -74,8 +74,8 @@ int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t po
return(state);
}
// SX1231 V2a only
if(this->chipRevision == RADIOLIB_SX1231_CHIP_REVISION_2_A) {
// SX123x V2a only
if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) {
// modify default OOK threshold value
state = this->mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
RADIOLIB_ASSERT(state);

Wyświetl plik

@ -8,9 +8,9 @@
#include "../../Module.h"
#include "../RF69/RF69.h"
#define RADIOLIB_SX1231_CHIP_REVISION_2_A 0x21
#define RADIOLIB_SX1231_CHIP_REVISION_2_B 0x22
#define RADIOLIB_SX1231_CHIP_REVISION_2_C 0x23
#define RADIOLIB_SX123X_CHIP_REVISION_2_A 0x21
#define RADIOLIB_SX123X_CHIP_REVISION_2_B 0x22
#define RADIOLIB_SX123X_CHIP_REVISION_2_C 0x23
// RADIOLIB_SX1231 specific register map
#define RADIOLIB_SX1231_REG_TEST_OOK 0x6E

Wyświetl plik

@ -0,0 +1,124 @@
#include "SX1233.h"
#if !RADIOLIB_EXCLUDE_SX1233
SX1233::SX1233(Module* mod) : SX1231(mod) {
}
int16_t SX1233::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) {
// set module properties
this->mod->init();
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
// try to find the SX1233 chip
uint8_t i = 0;
bool flagFound = false;
while((i < 10) && !flagFound) {
int16_t version = getChipVersion();
if((version == 0x21) || (version == 0x22) || (version == 0x23)) {
flagFound = true;
this->chipRevision = version;
} else {
RADIOLIB_DEBUG_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version);
this->mod->hal->delay(10);
i++;
}
}
if(!flagFound) {
RADIOLIB_DEBUG_PRINTLN("No SX1233 found!");
this->mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
}
RADIOLIB_DEBUG_PRINTLN("M\tSX1233");
// configure settings not accessible by API
int16_t state = config();
RADIOLIB_ASSERT(state);
RADIOLIB_DEBUG_PRINTLN("M\tRF69");
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
// configure bitrate
this->rxBandwidth = 125.0;
state = setBitRate(br);
RADIOLIB_ASSERT(state);
// configure default RX bandwidth
state = setRxBandwidth(rxBw);
RADIOLIB_ASSERT(state);
// configure default frequency deviation
state = setFrequencyDeviation(freqDev);
RADIOLIB_ASSERT(state);
// configure default TX output power
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
// configure default preamble length
state = setPreambleLength(preambleLen);
RADIOLIB_ASSERT(state);
// default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library
uint8_t syncWord[] = {0x2D, 0x01};
state = setSyncWord(syncWord, 2);
RADIOLIB_ASSERT(state);
// set default packet length mode
state = variablePacketLengthMode();
if (state != RADIOLIB_ERR_NONE) {
return(state);
}
// SX123x V2a only
if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) {
// modify default OOK threshold value
state = this->mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
RADIOLIB_ASSERT(state);
// enable OCP with 95 mA limit
state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0);
RADIOLIB_ASSERT(state);
}
return(RADIOLIB_ERR_NONE);
}
int16_t SX1233::setBitRate(float br) {
// check high bit-rate operation
uint8_t pllBandwidth = RADIOLIB_SX1233_PLL_BW_LOW_BIT_RATE;
if((fabs(br - 500.0f) < 0.1) || (fabs(br - 600.0f) < 0.1)) {
pllBandwidth = RADIOLIB_SX1233_PLL_BW_HIGH_BIT_RATE;
} else {
// datasheet says 1.2 kbps should be the smallest possible, but 0.512 works fine
RADIOLIB_CHECK_RANGE(br, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
}
// check bitrate-bandwidth ratio
if(!(br < 2000 * this->rxBandwidth)) {
return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
// set PLL bandwidth
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX1233_REG_TEST_PLL, pllBandwidth, 7, 0);
RADIOLIB_ASSERT(state);
// set bit rate
uint16_t bitRate = 32000 / br;
state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
if(state == RADIOLIB_ERR_NONE) {
this->bitRate = br;
}
return(state);
}
#endif

Wyświetl plik

@ -0,0 +1,59 @@
#if !defined(_RADIOLIB_SX1233_H)
#define _RADIOLIB_SX1233_H
#include "../../TypeDef.h"
#if !RADIOLIB_EXCLUDE_SX1233
#include "../../Module.h"
#include "../RF69/RF69.h"
#include "SX1231.h"
// RADIOLIB_SX1233 specific register map
#define RADIOLIB_SX1233_REG_TEST_PLL 0x5F
// RADIOLIB_SX1233_REG_TEST_PLL
#define RADIOLIB_SX1233_PLL_BW_HIGH_BIT_RATE 0x0C
#define RADIOLIB_SX1233_PLL_BW_LOW_BIT_RATE 0x08
/*!
\class SX1233
\brief Control class for %SX1233 module. Overrides some methods from SX1231/RF69 due to different register values.
*/
class SX1233: public SX1231 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
SX1233(Module* mod);
/*!
\brief Initialization method.
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
\param br Bit rate to be used in kbps. Defaults to 4.8 kbps.
\param freqDev Frequency deviation from carrier frequency in kHz Defaults to 5.0 kHz.
\param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz.
\param power Output power in dBm. Defaults to 10 dBm.
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16);
/*!
\brief Sets bit rate. Allowed values range from 0.5 to 300.0 kbps.
SX1233 also allows 500 kbps and 600 kbps operation.
\param br Bit rate to be set in kbps.
\returns \ref status_codes
*/
int16_t setBitRate(float br);
#if !RADIOLIB_GODMODE
private:
#endif
uint8_t chipRevision = 0;
};
#endif
#endif