SX1231 - reworked status codes

This commit is contained in:
Jan Gromeš 2018-07-23 12:42:33 +02:00
parent 0a90fc42d4
commit 75bb635370
4 changed files with 46 additions and 45 deletions

View file

@ -1,8 +1,8 @@
/* /*
* KiteLib SX1231 Receive Example KiteLib SX1231 Receive Example
*
* This example receives packets using SX1231 FSK radio module. This example receives packets using SX1231 FSK radio module.
*/ */
// include the library // include the library
#include <KiteLib.h> #include <KiteLib.h>
@ -22,12 +22,12 @@ void setup() {
// output power: 13 dBm // output power: 13 dBm
// sync word: 0x2D 0x01 // sync word: 0x2D 0x01
byte state = rf.begin(); byte state = rf.begin();
if(state == ERR_NONE) { if (state == ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code 0x")); Serial.print(F("failed, code "));
Serial.println(state, HEX); Serial.println(state);
while(true); while (true);
} }
// you can change the sync word at runtime // you can change the sync word at runtime
@ -38,9 +38,9 @@ void setup() {
// length: 2 // length: 2
// tolerated error bits: 0 // tolerated error bits: 0
state == rf.setSyncWord(syncWord, 2); state == rf.setSyncWord(syncWord, 2);
if(state == ERR_NONE) { if (state == ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else if(state == ERR_INVALID_SYNC_WORD) { } else if (state == ERR_INVALID_SYNC_WORD) {
Serial.println(F("invalid!")); Serial.println(F("invalid!"));
} }
} }
@ -50,15 +50,15 @@ void loop() {
// you can receive data as an Arduino String // you can receive data as an Arduino String
String str; String str;
byte state = rf.receive(str); int state = rf.receive(str);
// you can also receive data as byte array // you can also receive data as byte array
/* /*
byte byteArr[8]; byte byteArr[8];
byte state = rf.receive(byteArr, 8); int state = rf.receive(byteArr, 8);
*/ */
if(state == ERR_NONE) { if (state == ERR_NONE) {
// packet was successfully received // packet was successfully received
Serial.println(F("success!")); Serial.println(F("success!"));
@ -66,11 +66,11 @@ void loop() {
Serial.print(F("[SX1231] Data:\t\t")); Serial.print(F("[SX1231] Data:\t\t"));
Serial.println(str); Serial.println(str);
} else if(state == ERR_RX_TIMEOUT) { } else if (state == ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet // timeout occurred while waiting for a packet
Serial.println(F("timeout!")); Serial.println(F("timeout!"));
} else if(state == ERR_CRC_MISMATCH) { } else if (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed // packet was received, but is malformed
Serial.println(F("CRC error!")); Serial.println(F("CRC error!"));

View file

@ -1,8 +1,8 @@
/* /*
* KiteLib SX1231 Transmit Example KiteLib SX1231 Transmit Example
*
* This example transmits packets using SX1231 FSK radio module. This example transmits packets using SX1231 FSK radio module.
*/ */
// include the library // include the library
#include <KiteLib.h> #include <KiteLib.h>
@ -21,13 +21,13 @@ void setup() {
// frequency deviation: 50.0 kHz // frequency deviation: 50.0 kHz
// output power: 13 dBm // output power: 13 dBm
// sync word: 0x2D 0x01 // sync word: 0x2D 0x01
byte state = rf.begin(); int state = rf.begin();
if(state == ERR_NONE) { if (state == ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code 0x")); Serial.print(F("failed, code "));
Serial.println(state, HEX); Serial.println(state);
while(true); while (true);
} }
// you can change the sync word at runtime // you can change the sync word at runtime
@ -38,9 +38,9 @@ void setup() {
// length: 2 // length: 2
// tolerated error bits: 0 // tolerated error bits: 0
state == rf.setSyncWord(syncWord, 2); state == rf.setSyncWord(syncWord, 2);
if(state == ERR_NONE) { if (state == ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else if(state == ERR_INVALID_SYNC_WORD) { } else if (state == ERR_INVALID_SYNC_WORD) {
Serial.println(F("invalid!")); Serial.println(F("invalid!"));
} }
} }
@ -49,19 +49,19 @@ void loop() {
Serial.print(F("[SX1231] Transmitting packet ... ")); Serial.print(F("[SX1231] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 256 characters long // you can transmit C-string or Arduino string up to 256 characters long
byte state = rf.transmit("Hello World!"); int state = rf.transmit("Hello World!");
// you can also transmit byte array up to 256 bytes long // you can also transmit byte array up to 256 bytes long
/* /*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
byte state = rf.transmit(byteArr, 8); int state = rf.transmit(byteArr, 8);
*/ */
if(state == ERR_NONE) { if (state == ERR_NONE) {
// the packet was successfully transmitted // the packet was successfully transmitted
Serial.println(" success!"); Serial.println(" success!");
} else if(state == ERR_PACKET_TOO_LONG) { } else if (state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes // the supplied packet was longer than 256 bytes
Serial.println(" too long!"); Serial.println(" too long!");

View file

@ -4,7 +4,7 @@ SX1231::SX1231(Module* mod) : RF69(mod) {
} }
uint8_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t power) { int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t power) {
// set module properties // set module properties
_mod->init(USE_SPI, INT_BOTH); _mod->init(USE_SPI, INT_BOTH);
@ -18,13 +18,14 @@ uint8_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po
_chipRevision = version; _chipRevision = version;
} else { } else {
#ifdef KITELIB_DEBUG #ifdef KITELIB_DEBUG
Serial.print("SX1231 not found! ("); Serial.print(F("SX127x not found! ("));
Serial.print(i + 1); Serial.print(i + 1);
Serial.print(" of 10 tries) RF69_REG_VERSION == "); Serial.print(F(" of 10 tries) SX127X_REG_VERSION == "));
char buffHex[5]; char buffHex[7];
sprintf(buffHex, "0x%02X", version); sprintf(buffHex, "0x%04X", version);
Serial.print(buffHex); Serial.print(buffHex);
Serial.print(F(", expected 0x0021 / 0x0022 / 0x0023"));
Serial.println(); Serial.println();
#endif #endif
delay(1000); delay(1000);
@ -41,7 +42,7 @@ uint8_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t po
} }
// configure settings not accessible by API // configure settings not accessible by API
uint8_t state = config(); int16_t state = config();
if(state != ERR_NONE) { if(state != ERR_NONE) {
return(state); return(state);
} }

View file

@ -21,7 +21,7 @@ class SX1231: public RF69 {
SX1231(Module* mod); SX1231(Module* mod);
// basic methods // basic methods
uint8_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13); int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13);
private: private:
uint8_t _chipRevision; uint8_t _chipRevision;