Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
LSatan authored Aug 16, 2020
1 parent e538a56 commit ca16360
Show file tree
Hide file tree
Showing 39 changed files with 1,059 additions and 70 deletions.
475 changes: 444 additions & 31 deletions ELECHOUSE_CC1101_SRC_DRV.cpp

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions ELECHOUSE_CC1101_SRC_DRV.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class ELECHOUSE_CC1101
void setSpi(void);
void RegConfigSettings(void);
void Calibrate(void);
void Split_PKTCTRL0(void);
void Split_PKTCTRL1(void);
void Split_MDMCFG1(void);
void Split_MDMCFG2(void);
void Split_MDMCFG4(void);
public:
void Init(void);
byte SpiReadStatus(byte addr);
Expand All @@ -133,21 +138,42 @@ class ELECHOUSE_CC1101
void setModulation(byte m);
void setPA(int p);
void setMHZ(float mhz);
void setRxBW(byte RxBW);
void setChannel(byte chnl);
void setChsp(float f);
void setRxBW(float f);
void setDRate(float d);
void setDeviation(float d);
void SetTx(void);
void SetRx(void);
void SetTx(float mhz);
void SetRx(float mhz);
byte getRssi(void);
int getRssi(void);
byte getLqi(void);
void setSres(void);
void SendData(byte *txBuffer, byte size);
void SendData(char *txchar);
byte CheckReceiveFlag(void);
byte ReceiveData(byte *rxBuffer);
bool CheckCRC(void);
void SpiStrobe(byte strobe);
void SpiWriteReg(byte addr, byte value);
void setClb(byte b, byte s, byte e);
void setSyncWord(byte sh, byte sl);
void setAddr(byte v);
void setWhiteData(bool v);
void setPktFormat(byte v);
void setCrc(bool v);
void setLengthConfig(byte v);
void setPacketLength(byte v);
void setDcFilterOff(bool v);
void setManchester(bool v);
void setSyncMode(byte v);
void setFEC(bool v);
void setPQT(byte v);
void setCRC_AF(bool v);
void setAppendStatus(bool v);
void setAdrChk(byte v);
bool CheckRxFifo(int t);
};

extern ELECHOUSE_CC1101 ELECHOUSE_cc1101;
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SmartRC-CC1101-Driver-Lib_V2.4.0
# SmartRC-CC1101-Driver-Lib_V2.5.0

Note: Find out about the laws in your country.
Use at your own risk.
Expand Down Expand Up @@ -69,7 +69,8 @@ Description: CC1101 Internal send / receive examples. Supported modulations 2-FS
Instructions / Description:
---------------------------------------------
This driver library can be used for many libraries that use a simple RF ASK module,
with the advantages of the cc1101 module.
with the advantages of the cc1101 module.It offers many direct setting options as in
SmartRF Studio and calculates settings such as MHz directly.

The most important functions at a glance:

Expand Down Expand Up @@ -126,6 +127,20 @@ https://www.paypal.me/LittleSatan666

Thank You!

---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.0
---------------------------------------------
16.08.2020

Driver Library :Rssi was calculated incorrectly.Fixed Thanks to zapquiyou!

Driver Library :New receiving method for internal examples added. Allows several actions to be carried out in the loop.

Driver Library :Internal Crc check added for internal examples.

Driver Library :Simplification to send char added for internal transfer examples.

Driver Library :A lot of new settings added for internal transmission examples. Everything can be set as in SmartRF Studio and is calculated automatically. An overview: setDeviation, setChsp, setRxBW, setDRate, setSyncMode, setSyncWord, setAdrChk, setAddr, setWhiteData, setPktFormat, setLengthConfig, setPacketLength, setCrc, setCRC_AF, setDcFilterOff, setManchester, setFEC, setPQT, setAppendStatus. description in the examples!

---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.4.0
Expand All @@ -138,7 +153,6 @@ Driver Library :Added frequency calibration option.

Driver Library :Certain frequencies could not be set. Fixed! Big thanks to gusgorman402!


---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.3.5
---------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//New receiving method. This method checks the Rx Fifo for any data it contains.
//It allows you to do several things in a loop.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>

//int gdo0;

const int n = 61;

void setup(){
/*
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
*/
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
// ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
ELECHOUSE_cc1101.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
ELECHOUSE_cc1101.setPA(10); // Set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
ELECHOUSE_cc1101.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.

ELECHOUSE_cc1101.SetRx(); // set Receive on.

Serial.println("Rx Mode");
}

byte buffer[61] = {0};

void loop(){



//Checks whether something has been received.
//When something is received we give some time to receive the message in full.(time in millis)
if (ELECHOUSE_cc1101.CheckRxFifo(100)){

//CRC Check. If "setCrc(false)" crc returns always OK!
if (ELECHOUSE_cc1101.CheckCRC()){

//Rssi Level in dBm
Serial.print("Rssi: ");
Serial.println(ELECHOUSE_cc1101.getRssi());

//Link Quality Indicator
Serial.print("LQI: ");
Serial.println(ELECHOUSE_cc1101.getLqi());

//Get received Data and calculate length
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
buffer[len] = '\0';

//Print received in char format.
Serial.println((char *) buffer);

//Print received in bytes format.
for (int i = 0; i<len; i++){
Serial.print(buffer[i]);
Serial.print(",");
}
Serial.println();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//New receiving method. This method checks the Rx Fifo for any data it contains.
//It allows you to do several things in a loop.
//In addition, the gdo0 and gdo2 pin are not required.
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
//by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>

//int gdo0;

const int n = 61;

void setup(){
/*
#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif
*/
Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
// ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.SetRx(); // set Receive on.
Serial.println("Rx Mode");
}
byte buffer[61] = {0};

void loop(){

//Checks whether something has been received.
//When something is received we give some time to receive the message in full.(time in millis)
if (ELECHOUSE_cc1101.CheckRxFifo(100)){

if (ELECHOUSE_cc1101.CheckCRC()){ //CRC Check. If "setCrc(false)" crc returns always OK!
Serial.print("Rssi: ");
Serial.println(ELECHOUSE_cc1101.getRssi());
Serial.print("LQI: ");
Serial.println(ELECHOUSE_cc1101.getLqi());

int len = ELECHOUSE_cc1101.ReceiveData(buffer);
buffer[len] = '\0';
Serial.println((char *) buffer);
for (int i = 0; i<len; i++){
Serial.print(buffer[i]);
Serial.print(",");
}
Serial.println();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// These examples are from the Electronics Cookbook by Simon Monk
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
// mod by Little_S@tan
#include <ELECHOUSE_CC1101_SRC_DRV.h>
int gdo0;

const int n = 61;

void setup(){

#ifdef ESP32
gdo0 = 2; // for esp32! GDO0 on GPIO pin 2.
#elif ESP8266
gdo0 = 5; // for esp8266! GDO0 on pin 5 = D1.
#else
gdo0 = 6; // for Arduino! GDO0 on pin 6.
#endif

Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
ELECHOUSE_cc1101.setGDO(gdo0,0); // set lib internal gdo pins (gdo0,gdo2). Gdo2 not use for this example.
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
ELECHOUSE_cc1101.setMHZ(433.92); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
ELECHOUSE_cc1101.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
ELECHOUSE_cc1101.setChsp(199.95); // The channel spacing is multiplied by the channel number CHAN and added to the base frequency in kHz. Value from 25.39 to 405.45. Default is 199.95 kHz.
ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
ELECHOUSE_cc1101.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
ELECHOUSE_cc1101.setPA(10); // Set TxPower. The following settings are possible depending on the frequency band. (-30 -20 -15 -10 -6 0 5 7 10 11 12) Default is max!
ELECHOUSE_cc1101.setSyncMode(2); // Combined sync-word qualifier mode. 0 = No preamble/sync. 1 = 16 sync word bits detected. 2 = 16/16 sync word bits detected. 3 = 30/32 sync word bits detected. 4 = No preamble/sync, carrier-sense above threshold. 5 = 15/16 + carrier-sense above threshold. 6 = 16/16 + carrier-sense above threshold. 7 = 30/32 + carrier-sense above threshold.
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
ELECHOUSE_cc1101.setAdrChk(0); // Controls address check configuration of received packages. 0 = No address check. 1 = Address check, no broadcast. 2 = Address check and 0 (0x00) broadcast. 3 = Address check and 0 (0x00) and 255 (0xFF) broadcast.
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
ELECHOUSE_cc1101.setPktFormat(0); // Format of RX and TX data. 0 = Normal mode, use FIFOs for RX and TX. 1 = Synchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins. 2 = Random TX mode; sends random data using PN9 generator. Used for test. Works as normal mode, setting 0 (00), in RX. 3 = Asynchronous serial mode, Data in on GDO0 and data out on either of the GDOx pins.
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
ELECHOUSE_cc1101.setPacketLength(0); // Indicates the packet length when fixed packet length mode is enabled. If variable packet length mode is used, this value indicates the maximum packet length allowed.
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
ELECHOUSE_cc1101.setCRC_AF(0); // Enable automatic flush of RX FIFO when CRC is not OK. This requires that only one packet is in the RXIFIFO and that packet length is limited to the RX FIFO size.
ELECHOUSE_cc1101.setDcFilterOff(0); // Disable digital DC blocking filter before demodulator. Only for data rates ≤ 250 kBaud The recommended IF frequency changes when the DC blocking is disabled. 1 = Disable (current optimized). 0 = Enable (better sensitivity).
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setFEC(0); // Enable Forward Error Correction (FEC) with interleaving for packet payload (Only supported for fixed packet length mode. 0 = Disable. 1 = Enable.
ELECHOUSE_cc1101.setPQT(0); // Preamble quality estimator threshold. The preamble quality estimator increases an internal counter by one each time a bit is received that is different from the previous bit, and decreases the counter by 8 each time a bit is received that is the same as the last bit. A threshold of 4∙PQT for this counter is used to gate sync word detection. When PQT=0 a sync word is always accepted.
ELECHOUSE_cc1101.setAppendStatus(0); // When enabled, two status bytes will be appended to the payload of the packet. The status bytes contain RSSI and LQI values, as well as CRC OK.

ELECHOUSE_cc1101.SetRx(); // set Receive on.

Serial.println("Rx Mode");
}

byte buffer[61] = {0};

void loop(){

//Checks whether something has been received.
if (ELECHOUSE_cc1101.CheckReceiveFlag()){

//CRC Check. If "setCrc(false)" crc returns always OK!
if (ELECHOUSE_cc1101.CheckCRC()){

//Rssi Level in dBm
Serial.print("Rssi: ");
Serial.println(ELECHOUSE_cc1101.getRssi());

//Link Quality Indicator
Serial.print("LQI: ");
Serial.println(ELECHOUSE_cc1101.getLqi());

//Get received Data and calculate length
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
buffer[len] = '\0';

//Print received in char format.
Serial.println((char *) buffer);

//Print received in bytes format.
for (int i = 0; i<len; i++){
Serial.print(buffer[i]);
Serial.print(",");
}
Serial.println();
}
}
}
Loading

0 comments on commit ca16360

Please sign in to comment.