CC1101

From ElectroDragon
Jump to: navigation, search

Using With Arduino

CC1101 Pins Arduino Pins Description
SCK Arduino SCK PIN13 Clock Pin
SI Arduino MISO Pin12 Data input
SO Arduino MOSI Pin11 Data output
SS Arduino SS Pin10 Chip select
GDO2 Arduino Pin 9 output as a symbol of receiving or sending data
GDO0 Arduino Pin 2 serial clock output
VCC 3.3/5V Arduino VCC 3.3/5V VCC
GND GND Ground
  • Connect SPI to arduino SPI pins
  • Demo code available in documents section below
  • This is the demo code, you may need to add some delays (delay(3000);) to slow down the serial output

Arduino Library Panstamp Use Guide

  • Wiring to arduino, use the same pin as the table above, only NC for GDO2
Cc1101 2 bb.png
  • Find panstamp arduino library below

Demo Sketch

Transmitting The demo code will send a counter from 0 - 50 in hex to the receiver, data length of 10, counter on second byte

 
#include "EEPROM.h"
#include "cc1101.h"
 
CC1101 cc1101;
 
// The LED is wired to the Arduino Output 4 (physical panStamp pin 19)
#define LEDOUTPUT 13
 
// counter to get increment in each loop
byte counter;
byte b;
byte syncWord = 199;
 
void blinker(){
digitalWrite(LEDOUTPUT, HIGH);
delay(100);
digitalWrite(LEDOUTPUT, LOW);
delay(100);
}
 
void setup()
{
Serial.begin(9600);
Serial.println("start");
 
// setup the blinker output
pinMode(LEDOUTPUT, OUTPUT);
digitalWrite(LEDOUTPUT, LOW);
 
// blink once to signal the setup
blinker();
 
// reset the counter
counter=0;
Serial.println("initializing...");
// initialize the RF Chip
cc1101.init();
 
cc1101.setSyncWord(&syncWord, false);
cc1101.setCarrierFreq(CFREQ_433);
cc1101.disableAddressCheck();
//cc1101.setTxPowerAmp(PA_LowPower);
 
delay(1000);
 
Serial.print("CC1101_PARTNUM "); //cc1101=0
Serial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));
Serial.print("CC1101_VERSION "); //cc1101=4
Serial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));
Serial.print("CC1101_MARCSTATE ");
Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & 0x1f);
 
Serial.println("device initialized");
//Serial.println("done");
}
 
void send_data() {
CCPACKET data;
data.length=10;
byte blinkCount=counter++;
data.data[0]=5;
data.data[1]=blinkCount;data.data[2]=0;
data.data[3]=1;data.data[4]=0;
//cc1101.flushTxFifo ();
Serial.print("CC1101_MARCSTATE ");
Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & 0x1f);
if(cc1101.sendData(data)){
Serial.print(blinkCount,HEX);
Serial.println(" sent ok :)");
blinker();
}else{
Serial.println("sent failed :(");
blinker();
blinker();
}
}
 
void loop()
{
send_data();
delay(4000);
}

Receiving

#include "EEPROM.h"
#include "cc1101.h"
 
// The LED is wired to the Arduino Output 4 (physical panStamp pin 19)
#define LEDOUTPUT 4
 
// The connection to the hardware chip CC1101 the RF Chip
CC1101 cc1101;
 
byte b;
byte i;
byte syncWord = 199;
long counter = 0;
byte chan = 0;
 
// a flag that a wireless packet has been received
boolean packetAvailable = false;
 
void blinker() {
  digitalWrite(LEDOUTPUT, HIGH);
  delay(100);
  digitalWrite(LEDOUTPUT, LOW);
  delay(100);
}
 
/* Handle interrupt from CC1101 (INT0) gdo0 on pin2 */
void cc1101signalsInterrupt(void) {
  // set the flag that a package is available
  packetAvailable = true;
}
 
void setup()
{
  Serial.begin(9600);
  Serial.println("start");
 
  // setup the blinker output
  pinMode(LEDOUTPUT, OUTPUT);
  digitalWrite(LEDOUTPUT, LOW);
 
  // blink once to signal the setup
  blinker();
  // initialize the RF Chip
  cc1101.init();
 
  cc1101.setSyncWord(&syncWord, false);
  cc1101.setCarrierFreq(CFREQ_433);
  cc1101.disableAddressCheck(); //if not specified, will only display "packet received"
  //cc1101.setTxPowerAmp(PA_LowPower);
 
  Serial.print("CC1101_PARTNUM "); //cc1101=0
  Serial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));
  Serial.print("CC1101_VERSION "); //cc1101=4
  Serial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));
  Serial.print("CC1101_MARCSTATE ");
  Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER) & 0x1f);
 
  attachInterrupt(0, cc1101signalsInterrupt, FALLING);
 
  Serial.println("device initialized");
}
 
void ReadLQI()
{
  byte lqi = 0;
  byte value = 0;
  lqi = (cc1101.readReg(CC1101_LQI, CC1101_STATUS_REGISTER));
  value = 0x3F - (lqi & 0x3F);
  Serial.print("CC1101_LQI ");
  Serial.println(value);
}
 
void ReadRSSI()
{
  byte rssi = 0;
  byte value = 0;
 
  rssi = (cc1101.readReg(CC1101_RSSI, CC1101_STATUS_REGISTER));
 
  if (rssi >= 128)
  {
    value = 255 - rssi;
    value /= 2;
    value += 74;
  }
  else
  {
    value = rssi / 2;
    value += 74;
  }
  Serial.print("CC1101_RSSI ");
  Serial.println(value);
}
 
void loop()
{
  if (packetAvailable) {
    Serial.println("packet received");
    // Disable wireless reception interrupt
    detachInterrupt(0);
 
    ReadRSSI();
    ReadLQI();
    // clear the flag
    packetAvailable = false;
 
    CCPACKET packet;
 
    if (cc1101.receiveData(&packet) > 0) {
      if (!packet.crc_ok) {
        Serial.println("crc not ok");
      }
 
      if (packet.length > 0) {
        Serial.print("packet: len ");
        Serial.print(packet.length);
        Serial.print(" data: ");
        for (int j = 0; j < packet.length; j++) {
          Serial.print(packet.data[j], HEX);
          Serial.print(" ");
        }
        Serial.println(".");
      }
    }
    // Enable wireless reception interrupt
    attachInterrupt(0, cc1101signalsInterrupt, FALLING);
  }
}

CC1101 UART Board

Pin definition from Front View, From left to right

Pins Definition Description connect to P.S
1 Sleep Sleep mode - This function is not designed yet
2 Reset Reset Not necessary to connect -
3 VCC Power +2.7V~5.5V Recommended +4.5~+5.5V
4 Rx Data input UART data input TTL
5 Tx Data output UART data output TTL
6 GND GND GND -

Setting

Commands Commands + Data Example note
Set operation frequency A7,7A + 00 send A7 7A 06, the channel will be set to 6 Channel value from 0×00~0xEE, 238 channels in total
Set baud rate A3, 3A + 01 send A3 3A 03 set the baud rate to 19200 01:4800, 02:9600, 03:19200
Set operation power AB,BA + 00 send AB BA 0A, set the operation transmission power to 10dBM Transmission power can be 0、5、7、10dBM
Set module ID A9, 9A + 00 09 send A9 9A 00 08, set the module ID to 8, this ID are stored in EEPROM If the ID need to be converted into hex first
Read module specification A6, 6A send A6, 6A, return A6 00 64 02 0A 00 00 = The initial code returned, Operation channels, Data speed 100Kbps, 02 Means the baud rate is 9600, Transmission Power is 10dBm, Module ID
  • Default settings, Operation channel = 0, Data speed = 100kbps, Baud rate = 9600, Transmission Power = 10mW, Module ID = 00 00
  • Note: Send only less than 30 bytes data each time, otherwise it will not succeed

Documents

Demo Code for Arduino

Panstamp arduino Library

  • Download the library here: File:Panstamp.zip, please only use this file, the new version of panstamp can not work well.
  • The initial thread on the Arduino forum.

CC1101 datasheet

CC1101 UART version

SmartRF