Skip to content

Commit e5365d3

Browse files
authored
Add files via upload
1 parent 7bd6baa commit e5365d3

File tree

18 files changed

+753
-12
lines changed

18 files changed

+753
-12
lines changed

ELECHOUSE_CC1101_SRC_DRV.cpp

+39-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ byte pc0WDATA;
5454
byte pc0PktForm;
5555
byte pc0CRC_EN;
5656
byte pc0LenConf;
57+
byte trxstate;
5758
byte clb1[2]= {24,28};
5859
byte clb2[2]= {31,38};
5960
byte clb3[2]= {65,76};
@@ -141,7 +142,6 @@ void ELECHOUSE_CC1101::Init(void)
141142
{
142143
setSpi();
143144
SpiStart(); //spi initialization
144-
GDO_Set(); //GDO set
145145
digitalWrite(SS_PIN, HIGH);
146146
digitalWrite(SCK_PIN, HIGH);
147147
digitalWrite(MOSI_PIN, LOW);
@@ -305,6 +305,7 @@ void ELECHOUSE_CC1101::setSpiPin(byte sck, byte miso, byte mosi, byte ss){
305305
void ELECHOUSE_CC1101::setGDO(byte gdo0, byte gdo2){
306306
GDO0 = gdo0;
307307
GDO2 = gdo2;
308+
GDO_Set();
308309
}
309310
/****************************************************************
310311
*FUNCTION NAME:CCMode
@@ -526,7 +527,7 @@ clb4[1]=e;
526527
}
527528
}
528529
/****************************************************************
529-
*FUNCTION NAME:Set Sync_Worf
530+
*FUNCTION NAME:Set Sync_Word
530531
*FUNCTION :Sync Word
531532
*INPUT :none
532533
*OUTPUT :none
@@ -949,6 +950,7 @@ void ELECHOUSE_CC1101::SetTx(void)
949950
{
950951
SpiStrobe(CC1101_SIDLE);
951952
SpiStrobe(CC1101_STX); //start send
953+
trxstate=1;
952954
}
953955
/****************************************************************
954956
*FUNCTION NAME:SetRx
@@ -959,6 +961,7 @@ void ELECHOUSE_CC1101::SetTx(void)
959961
void ELECHOUSE_CC1101::SetRx(void)
960962
{
961963
SpiStrobe(CC1101_SRX); //start receive
964+
trxstate=2;
962965
}
963966
/****************************************************************
964967
*FUNCTION NAME:SetTx
@@ -971,6 +974,7 @@ void ELECHOUSE_CC1101::SetTx(float mhz)
971974
setMHZ(mhz);
972975
SpiStrobe(CC1101_SIDLE);
973976
SpiStrobe(CC1101_STX); //start send
977+
trxstate=1;
974978
}
975979
/****************************************************************
976980
*FUNCTION NAME:SetRx
@@ -982,6 +986,7 @@ void ELECHOUSE_CC1101::SetRx(float mhz)
982986
{
983987
setMHZ(mhz);
984988
SpiStrobe(CC1101_SRX); //start receive
989+
trxstate=2;
985990
}
986991
/****************************************************************
987992
*FUNCTION NAME:RSSI Level
@@ -1047,6 +1052,36 @@ void ELECHOUSE_CC1101::SendData(byte *txBuffer,byte size)
10471052
while (!digitalRead(GDO0)); // Wait for GDO0 to be set -> sync transmitted
10481053
while (digitalRead(GDO0)); // Wait for GDO0 to be cleared -> end of packet
10491054
SpiStrobe(CC1101_SFTX); //flush TXfifo
1055+
trxstate=1;
1056+
}
1057+
/****************************************************************
1058+
*FUNCTION NAME:Char direct SendData
1059+
*FUNCTION :use CC1101 send data without GDO
1060+
*INPUT :txBuffer: data array to send; size: number of data to send, no more than 61
1061+
*OUTPUT :none
1062+
****************************************************************/
1063+
void ELECHOUSE_CC1101::SendData(char *txchar,int t)
1064+
{
1065+
int len = strlen(txchar);
1066+
byte chartobyte[len];
1067+
for (int i = 0; i<len; i++){chartobyte[i] = txchar[i];}
1068+
SendData(chartobyte,len,t);
1069+
}
1070+
/****************************************************************
1071+
*FUNCTION NAME:SendData
1072+
*FUNCTION :use CC1101 send data without GDO
1073+
*INPUT :txBuffer: data array to send; size: number of data to send, no more than 61
1074+
*OUTPUT :none
1075+
****************************************************************/
1076+
void ELECHOUSE_CC1101::SendData(byte *txBuffer,byte size,int t)
1077+
{
1078+
SpiWriteReg(CC1101_TXFIFO,size);
1079+
SpiWriteBurstReg(CC1101_TXFIFO,txBuffer,size); //write data to send
1080+
SpiStrobe(CC1101_SIDLE);
1081+
SpiStrobe(CC1101_STX); //start send
1082+
delay(t);
1083+
SpiStrobe(CC1101_SFTX); //flush TXfifo
1084+
trxstate=1;
10501085
}
10511086
/****************************************************************
10521087
*FUNCTION NAME:Check CRC
@@ -1072,6 +1107,7 @@ return 0;
10721107
*OUTPUT :flag: 0 no data; 1 receive data
10731108
****************************************************************/
10741109
bool ELECHOUSE_CC1101::CheckRxFifo(int t){
1110+
if(trxstate!=2){SetRx();}
10751111
if(SpiReadStatus(CC1101_RXBYTES) & BYTES_IN_RXFIFO){
10761112
delay(t);
10771113
return 1;
@@ -1087,6 +1123,7 @@ return 0;
10871123
****************************************************************/
10881124
byte ELECHOUSE_CC1101::CheckReceiveFlag(void)
10891125
{
1126+
if(trxstate!=2){SetRx();}
10901127
if(digitalRead(GDO0)) //receive data
10911128
{
10921129
while (digitalRead(GDO0));

ELECHOUSE_CC1101_SRC_DRV.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ class ELECHOUSE_CC1101
118118
void SpiEnd(void);
119119
void GDO_Set (void);
120120
void Reset (void);
121-
void SpiWriteBurstReg(byte addr, byte *buffer, byte num);
122-
byte SpiReadReg(byte addr);
123-
void SpiReadBurstReg(byte addr, byte *buffer, byte num);
124121
void setSpi(void);
125122
void RegConfigSettings(void);
126123
void Calibrate(void);
@@ -152,11 +149,16 @@ class ELECHOUSE_CC1101
152149
void setSres(void);
153150
void SendData(byte *txBuffer, byte size);
154151
void SendData(char *txchar);
152+
void SendData(byte *txBuffer, byte size, int t);
153+
void SendData(char *txchar, int t);
155154
byte CheckReceiveFlag(void);
156155
byte ReceiveData(byte *rxBuffer);
157156
bool CheckCRC(void);
158157
void SpiStrobe(byte strobe);
159158
void SpiWriteReg(byte addr, byte value);
159+
void SpiWriteBurstReg(byte addr, byte *buffer, byte num);
160+
byte SpiReadReg(byte addr);
161+
void SpiReadBurstReg(byte addr, byte *buffer, byte num);
160162
void setClb(byte b, byte s, byte e);
161163
void setSyncWord(byte sh, byte sl);
162164
void setAddr(byte v);

README.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SmartRC-CC1101-Driver-Lib_V2.5.1
1+
# SmartRC-CC1101-Driver-Lib_V2.5.2
22

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

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

33-
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.
34-
35-
There will be a second library that has a larger set of functions and accordingly takes up more memory.
36-
3733
I would be happy to receive your suggestions for further examples from other libraries.
3834

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

132128
Thank You!
133129

130+
---------------------------------------------
131+
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.2
132+
---------------------------------------------
133+
01.10.2020
134+
135+
Driver Library :SpiWriteReg, SpiReadReg, SpiWriteBurstReg and SpiReadBurstReg change to public. Allows additional modifications from sketch.
136+
137+
Driver Library :Setrx no longer has to be set to receive.(internal transmission methods)
138+
139+
Driver Library :Gdo pins are now set to input / output with set gdo instead of Init.
140+
141+
Driver Library :Added new sending method. Allows sending without a gdo0 pin.
142+
143+
notes :The new internal send and receive methods now work completely without an additional gdo pin.
144+
134145
---------------------------------------------
135146
Changelog: SmartRC-CC1101-Driver-Lib_V2.5.1
136147
---------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//New receiving method. This method checks the Rx Fifo for any data it contains.
2+
//It allows you to do several things in a loop.
3+
//In addition, the gdo0 and gdo2 pin are not required.
4+
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
5+
//by Little_S@tan
6+
#include <ELECHOUSE_CC1101_SRC_DRV.h>
7+
8+
void setup(){
9+
10+
Serial.begin(9600);
11+
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
12+
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
13+
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
14+
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.
15+
ELECHOUSE_cc1101.setDeviation(47.60); // Set the Frequency deviation in kHz. Value from 1.58 to 380.85. Default is 47.60 kHz.
16+
ELECHOUSE_cc1101.setChannel(0); // Set the Channelnumber from 0 to 255. Default is cahnnel 0.
17+
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.
18+
ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
19+
ELECHOUSE_cc1101.setDRate(99.97); // Set the Data Rate in kBaud. Value from 0.02 to 1621.83. Default is 99.97 kBaud!
20+
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!
21+
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.
22+
ELECHOUSE_cc1101.setSyncWord(211, 145); // Set sync word. Must be the same for the transmitter and receiver. (Syncword high, Syncword low)
23+
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.
24+
ELECHOUSE_cc1101.setAddr(0); // Address used for packet filtration. Optional broadcast addresses are 0 (0x00) and 255 (0xFF).
25+
ELECHOUSE_cc1101.setWhiteData(0); // Turn data whitening on / off. 0 = Whitening off. 1 = Whitening on.
26+
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.
27+
ELECHOUSE_cc1101.setLengthConfig(1); // 0 = Fixed packet length mode. 1 = Variable packet length mode. 2 = Infinite packet length mode. 3 = Reserved
28+
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.
29+
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
30+
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.
31+
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).
32+
ELECHOUSE_cc1101.setManchester(0); // Enables Manchester encoding/decoding. 0 = Disable. 1 = Enable.
33+
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.
34+
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.
35+
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.
36+
37+
Serial.println("Rx Mode");
38+
}
39+
40+
byte buffer[61] = {0};
41+
42+
void loop(){
43+
44+
//Checks whether something has been received.
45+
//When something is received we give some time to receive the message in full.(time in millis)
46+
if (ELECHOUSE_cc1101.CheckRxFifo(100)){
47+
48+
//CRC Check. If "setCrc(false)" crc returns always OK!
49+
if (ELECHOUSE_cc1101.CheckCRC()){
50+
51+
//Rssi Level in dBm
52+
Serial.print("Rssi: ");
53+
Serial.println(ELECHOUSE_cc1101.getRssi());
54+
55+
//Link Quality Indicator
56+
Serial.print("LQI: ");
57+
Serial.println(ELECHOUSE_cc1101.getLqi());
58+
59+
//Get received Data and calculate length
60+
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
61+
buffer[len] = '\0';
62+
63+
//Print received in char format.
64+
Serial.println((char *) buffer);
65+
66+
//Print received in bytes format.
67+
for (int i = 0; i<len; i++){
68+
Serial.print(buffer[i]);
69+
Serial.print(",");
70+
}
71+
Serial.println();
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//New receiving method. This method checks the Rx Fifo for any data it contains.
2+
//It allows you to do several things in a loop.
3+
//In addition, the gdo0 and gdo2 pin are not required.
4+
//https://github.com/LSatan/SmartRC-CC1101-Driver-Lib
5+
//by Little_S@tan
6+
#include <ELECHOUSE_CC1101_SRC_DRV.h>
7+
8+
void setup(){
9+
10+
Serial.begin(9600);
11+
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
12+
ELECHOUSE_cc1101.setCCMode(1); // set config for internal transmission mode.
13+
ELECHOUSE_cc1101.setModulation(0); // set modulation mode. 0 = 2-FSK, 1 = GFSK, 2 = ASK/OOK, 3 = 4-FSK, 4 = MSK.
14+
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.
15+
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.
16+
ELECHOUSE_cc1101.setCrc(1); // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.
17+
18+
Serial.println("Rx Mode");
19+
}
20+
byte buffer[61] = {0};
21+
22+
void loop(){
23+
24+
//Checks whether something has been received.
25+
//When something is received we give some time to receive the message in full.(time in millis)
26+
if (ELECHOUSE_cc1101.CheckRxFifo(100)){
27+
28+
if (ELECHOUSE_cc1101.CheckCRC()){ //CRC Check. If "setCrc(false)" crc returns always OK!
29+
Serial.print("Rssi: ");
30+
Serial.println(ELECHOUSE_cc1101.getRssi());
31+
Serial.print("LQI: ");
32+
Serial.println(ELECHOUSE_cc1101.getLqi());
33+
34+
int len = ELECHOUSE_cc1101.ReceiveData(buffer);
35+
buffer[len] = '\0';
36+
Serial.println((char *) buffer);
37+
for (int i = 0; i<len; i++){
38+
Serial.print(buffer[i]);
39+
Serial.print(",");
40+
}
41+
Serial.println();
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)