How to do 2 way communication

I use CC1101 433MHz RF-module with PanStamp library to make a 2 way communication.

I have finished transmitting and receiving the data, like in the code below:

Transmitting:

#include <cc1101.h>
#include <EEPROM.h>
#include <Wire.h>
#include <PS2X_lib.h>

// Create a objekct
CC1101 cc1101;

PS2X ps2x;


// VARIABELS
int error = 0;
byte type = 0;
  
// counter to get increment in each loop
byte counter;
byte b;
byte syncWord = 199;
 
 
void setup()
{
Serial.begin(9600);

error = ps2x.config_gamepad(9,8,7,6, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

  if(error == 0){
   Serial.println("Found Controller, configured successful");
  }
  
  else if(error == 1)
   Serial.println("No controller found, check wiring.");
   
  else if(error == 2)
   Serial.println("Controller found but not accepting commands.");
   
  else if(error == 3)
   Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
  
  type = ps2x.readType(); 
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
     }

Serial.println("starter RF");
 
 
// 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 loop()
{

ps2x.read_gamepad(false, false);          //read controller and set large motor to spin at 'vibrate' speed
  
CCPACKET data;
data.length=1;
//byte data = 0;
if(ps2x.ButtonPressed(PSB_RED)){             //will be TRUE if button was JUST pressed
         Serial.println("Circle just pressed");
        data.data[0] = 20;
        Serial.println(data.data[0]);
        cc1101.sendData(data);
       
}
else if(ps2x.ButtonReleased(PSB_RED)){             //will be TRUE if button was JUST released
         Serial.println("Circle just released");
        data.data[0] = 0;
        Serial.println(data.data[0]);
        cc1101.sendData(data);
}

}

Receiving:

#include <Wire.h>
#include <EEPROM.h>
#include "cc1101.h"
 
 
// The connection to the hardware chip CC1101 the RF Chip
CC1101 cc1101;


int j;
byte x; 
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;
 

 
/* Handle interrupt from CC1101 (INT0) gdo0 on pin2 */
void cc1101signalsInterrupt(void) {
  // set the flag that a package is available
  packetAvailable = true;
}
 
void setup()
{
  
  Wire.begin();

  Serial.begin(9600);
  Serial.println("start");
    
 
  // 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");
        
      }
      
      else if (packet.crc_ok){ 
      if (packet.length > 0) {
        Serial.print("packet: len ");
        Serial.print(packet.length);
        Serial.print(" data: ");

        j = 0;
        x = packet.data[j];
          Serial.print(x);
          Serial.print(" ");
          Wire.beginTransmission(4);// transmit to device #4
          Wire.write(x);              // sends one byte  
          Wire.endTransmission();    // stop tran 
        Serial.println(".");
        
      }
    }
    }
    // Enable wireless reception interrupt
    attachInterrupt(0, cc1101signalsInterrupt, FALLING);
  }

}

The CC1101 is a half-duplex type architecture. It cannot transmit while receiving, however it can switch between transmit and receive very quickly.

Then my question is should I implement a Chip Select to be able to communicate as transceiver? If yes, do you have please some idea how to do it? I,m pretty blank.

Then my question is should I implement a Chip Select to be able to communicate as transceiver?

How is the device connected to the Arduino? Which pins?

Chip select has meaning if the device uses SPI to communicate with the Arduino. There is no need to do more with a chip select pin to write to the device than you'd need to do to read from the device.

There are a attached files where you can see the pins of the cc1101, and how it is connected to the arduino. The CC1101 RF-module dose use SPI.

CC1101.PNG

CC1101Arduino.PNG

PaulS:

Then my question is should I implement a Chip Select to be able to communicate as transceiver?

How is the device connected to the Arduino? Which pins?

Chip select has meaning if the device uses SPI to communicate with the Arduino. There is no need to do more with a chip select pin to write to the device than you'd need to do to read from the device.

I have answered your question.

Hi,

I'm using an arduino mega 2650 and a cc1101 RF module and I can't get it working ! I followed this tutorial: Arduino : use a Texas CC1101 – Erwan's Blog but in the serial monitor all register values are 0 and packets not sent Sad
I have two questions:

  1. did you used tension regulator ? because I actually use it since on cc1101 the max voltage that can be on any digital pin is 3.9v but the high or low voltage levels for arduino correspond to +5v and 0v so if we directly connect the pins, it may cause a damage to cc1101 ?

  2. when using arduino mega, the GDO0 pin of the CC1101 must be connected to the pin 19 (RX1) of arduino and we change the value of #define GDO0 2 to #define GDO0 19 in spi.h of the panstamp library, right?

Thank you in advance.

Hello!

Do you know how to slightly change the frequency from 433 mhz to 433.68 mhz?

Do you know how to slightly change the frequency from 433 mhz to 433.68 mhz?

Unsolder the 433 MHz crystal and solder in a 433.68 MHz crystal in its place.

Krantz:
Hello!

Do you know how to slightly change the frequency from 433 mhz to 433.68 mhz?

cc1101.setChannel();

Add a number in () and it will move it up to the next channel