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 Oct 1, 2020
1 parent 7bd6baa commit e5365d3
Show file tree
Hide file tree
Showing 18 changed files with 753 additions and 12 deletions.
41 changes: 39 additions & 2 deletions ELECHOUSE_CC1101_SRC_DRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ byte pc0WDATA;
byte pc0PktForm;
byte pc0CRC_EN;
byte pc0LenConf;
byte trxstate;
byte clb1[2]= {24,28};
byte clb2[2]= {31,38};
byte clb3[2]= {65,76};
Expand Down Expand Up @@ -141,7 +142,6 @@ void ELECHOUSE_CC1101::Init(void)
{
setSpi();
SpiStart(); //spi initialization
GDO_Set(); //GDO set
digitalWrite(SS_PIN, HIGH);
digitalWrite(SCK_PIN, HIGH);
digitalWrite(MOSI_PIN, LOW);
Expand Down Expand Up @@ -305,6 +305,7 @@ void ELECHOUSE_CC1101::setSpiPin(byte sck, byte miso, byte mosi, byte ss){
void ELECHOUSE_CC1101::setGDO(byte gdo0, byte gdo2){
GDO0 = gdo0;
GDO2 = gdo2;
GDO_Set();
}
/****************************************************************
*FUNCTION NAME:CCMode
Expand Down Expand Up @@ -526,7 +527,7 @@ clb4[1]=e;
}
}
/****************************************************************
*FUNCTION NAME:Set Sync_Worf
*FUNCTION NAME:Set Sync_Word
*FUNCTION :Sync Word
*INPUT :none
*OUTPUT :none
Expand Down Expand Up @@ -949,6 +950,7 @@ void ELECHOUSE_CC1101::SetTx(void)
{
SpiStrobe(CC1101_SIDLE);
SpiStrobe(CC1101_STX); //start send
trxstate=1;
}
/****************************************************************
*FUNCTION NAME:SetRx
Expand All @@ -959,6 +961,7 @@ void ELECHOUSE_CC1101::SetTx(void)
void ELECHOUSE_CC1101::SetRx(void)
{
SpiStrobe(CC1101_SRX); //start receive
trxstate=2;
}
/****************************************************************
*FUNCTION NAME:SetTx
Expand All @@ -971,6 +974,7 @@ void ELECHOUSE_CC1101::SetTx(float mhz)
setMHZ(mhz);
SpiStrobe(CC1101_SIDLE);
SpiStrobe(CC1101_STX); //start send
trxstate=1;
}
/****************************************************************
*FUNCTION NAME:SetRx
Expand All @@ -982,6 +986,7 @@ void ELECHOUSE_CC1101::SetRx(float mhz)
{
setMHZ(mhz);
SpiStrobe(CC1101_SRX); //start receive
trxstate=2;
}
/****************************************************************
*FUNCTION NAME:RSSI Level
Expand Down Expand Up @@ -1047,6 +1052,36 @@ void ELECHOUSE_CC1101::SendData(byte *txBuffer,byte size)
while (!digitalRead(GDO0)); // Wait for GDO0 to be set -> sync transmitted
while (digitalRead(GDO0)); // Wait for GDO0 to be cleared -> end of packet
SpiStrobe(CC1101_SFTX); //flush TXfifo
trxstate=1;
}
/****************************************************************
*FUNCTION NAME:Char direct SendData
*FUNCTION :use CC1101 send data without GDO
*INPUT :txBuffer: data array to send; size: number of data to send, no more than 61
*OUTPUT :none
****************************************************************/
void ELECHOUSE_CC1101::SendData(char *txchar,int t)
{
int len = strlen(txchar);
byte chartobyte[len];
for (int i = 0; i<len; i++){chartobyte[i] = txchar[i];}
SendData(chartobyte,len,t);
}
/****************************************************************
*FUNCTION NAME:SendData
*FUNCTION :use CC1101 send data without GDO
*INPUT :txBuffer: data array to send; size: number of data to send, no more than 61
*OUTPUT :none
****************************************************************/
void ELECHOUSE_CC1101::SendData(byte *txBuffer,byte size,int t)
{
SpiWriteReg(CC1101_TXFIFO,size);
SpiWriteBurstReg(CC1101_TXFIFO,txBuffer,size); //write data to send
SpiStrobe(CC1101_SIDLE);
SpiStrobe(CC1101_STX); //start send
delay(t);
SpiStrobe(CC1101_SFTX); //flush TXfifo
trxstate=1;
}
/****************************************************************
*FUNCTION NAME:Check CRC
Expand All @@ -1072,6 +1107,7 @@ return 0;
*OUTPUT :flag: 0 no data; 1 receive data
****************************************************************/
bool ELECHOUSE_CC1101::CheckRxFifo(int t){
if(trxstate!=2){SetRx();}
if(SpiReadStatus(CC1101_RXBYTES) & BYTES_IN_RXFIFO){
delay(t);
return 1;
Expand All @@ -1087,6 +1123,7 @@ return 0;
****************************************************************/
byte ELECHOUSE_CC1101::CheckReceiveFlag(void)
{
if(trxstate!=2){SetRx();}
if(digitalRead(GDO0)) //receive data
{
while (digitalRead(GDO0));
Expand Down
8 changes: 5 additions & 3 deletions ELECHOUSE_CC1101_SRC_DRV.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ class ELECHOUSE_CC1101
void SpiEnd(void);
void GDO_Set (void);
void Reset (void);
void SpiWriteBurstReg(byte addr, byte *buffer, byte num);
byte SpiReadReg(byte addr);
void SpiReadBurstReg(byte addr, byte *buffer, byte num);
void setSpi(void);
void RegConfigSettings(void);
void Calibrate(void);
Expand Down Expand Up @@ -152,11 +149,16 @@ class ELECHOUSE_CC1101
void setSres(void);
void SendData(byte *txBuffer, byte size);
void SendData(char *txchar);
void SendData(byte *txBuffer, byte size, int t);
void SendData(char *txchar, int t);
byte CheckReceiveFlag(void);
byte ReceiveData(byte *rxBuffer);
bool CheckCRC(void);
void SpiStrobe(byte strobe);
void SpiWriteReg(byte addr, byte value);
void SpiWriteBurstReg(byte addr, byte *buffer, byte num);
byte SpiReadReg(byte addr);
void SpiReadBurstReg(byte addr, byte *buffer, byte num);
void setClb(byte b, byte s, byte e);
void setSyncWord(byte sh, byte sl);
void setAddr(byte v);
Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SmartRC-CC1101-Driver-Lib_V2.5.1
# SmartRC-CC1101-Driver-Lib_V2.5.2

Note: Find out about the laws in your country.
Use at your own risk.
Expand Down Expand Up @@ -30,10 +30,6 @@ The library has been redesigned and some improvements have been made.

Among other things, you can now also use the internal send / receive function.

With the exception of bug fixes and examples, there will be no major innovations for this library in the future to keep the library as small as possible.

There will be a second library that has a larger set of functions and accordingly takes up more memory.

I would be happy to receive your suggestions for further examples from other libraries.

All examples included are listed in the next field.
Expand Down Expand Up @@ -131,6 +127,21 @@ https://www.paypal.me/LittleSatan666

Thank You!

---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.2
---------------------------------------------
01.10.2020

Driver Library :SpiWriteReg, SpiReadReg, SpiWriteBurstReg and SpiReadBurstReg change to public. Allows additional modifications from sketch.

Driver Library :Setrx no longer has to be set to receive.(internal transmission methods)

Driver Library :Gdo pins are now set to input / output with set gdo instead of Init.

Driver Library :Added new sending method. Allows sending without a gdo0 pin.

notes :The new internal send and receive methods now work completely without an additional gdo pin.

---------------------------------------------
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.1
---------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//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>

void setup(){

Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
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.

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,44 @@
//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>

void setup(){

Serial.begin(9600);
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
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.

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();
}
}
}
Loading

0 comments on commit e5365d3

Please sign in to comment.