cc1101 + arduino

je continue à partager mon expérience sur le rf1100se / cc1101.

Apres avoir configuré les registres ca se comporte un peu mieux :
-le 1er senddata ne bloque plus mais me renvoie un failed
-le 2eme senddata bloque mais je crois que c'est le comportement normal a moins de modifier le bon flag

j'ai vérifié quelques registres en lecture, je retrouve bien mes valeurs passées en écriture, donc coté SPI tout va bien à priori.

Un module complexe mais qui offre plein d'options possibles.

Prochaine étape : un senddata avec succès :slight_smile:

ci dessous la sortie sur mon serial

start
initializing...
device initialized
loop...
sent failed :(0
loop done
loop...

ci dessous le code

#include "EEPROM.h"
#include "cc1101.h"

CC1101 cc1101;

// The LED is wired to the Arduino Output 4
#define LEDOUTPUT 4

// counter to get increment in each loop
byte counter;
byte b;

// PATABLE (0 dBm output power)
//char paTable[] = {0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// PATABLE (10 dBm output power)
char paTable[] = {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
/**
* Let the LED Output blink one time.
* 
* With small pause after the blink to see two consecutive blinks. 
*/
void blinker(){
      digitalWrite(LEDOUTPUT, HIGH);
      delay(100);
      digitalWrite(LEDOUTPUT, LOW);
      delay(100);
}

void config()
{
cc1101.writeReg(CC1101_FSCTRL1, 0x06); //0x06,  // FSCTRL1       Frequency Synthesizer Control - IF:152.343Khz
cc1101.writeReg(CC1101_IOCFG0, 0x07);  //0x07,  // IOCFG0        GDO0 Output Pin Configuration - Packet received and CRC OK  
cc1101.writeReg(CC1101_FSCTRL0, 0x00); //0x00,  // FSCTRL0       Frequency Synthesizer Control - Freq offset
cc1101.writeReg(CC1101_FREQ2, 0x10); //0x10,  // FREQ2         Frequency Control Word, High Byte - 433.999 Mhz
cc1101.writeReg(CC1101_FREQ1, 0xb1); //0xB1,  // FREQ1         Frequency Control Word, Middle Byte
cc1101.writeReg(CC1101_FREQ0, 0x3b);  //0x3B,  // FREQ0         Frequency Control Word, Low Byte
cc1101.writeReg(CC1101_MDMCFG4, 0xf8); //0xF8,  // MDMCFG4       Modem Configuration - BW: 58.035Khz
cc1101.writeReg(CC1101_MDMCFG3, 0x83);  //0x83,  // MDMCFG3       Modem Configuration - 9595 Baud  
cc1101.writeReg(CC1101_MDMCFG2, 0x13); //0x13,  // MDMCFG2       Modem Configuration - 30/32 sync word bits - Manchester disable - GFSK - Digital DC filter enable
cc1101.writeReg(CC1101_MDMCFG1, 0x22); //0x22,  // MDMCFG1       Modem Configuration - num of preamble bytes:4 - FEC disable
cc1101.writeReg(CC1101_MDMCFG0, 0xf8); //0xF8,  // MDMCFG0       Modem Configuration - Channel spacing: 199.951Khz
cc1101.writeReg(CC1101_CHANNR, 0x00); //0x00,  // CHANNR        Channel Number
cc1101.writeReg(CC1101_DEVIATN, 0x15);  //0x15,  // DEVIATN       Modem Deviation Setting - 5.157Khz   
cc1101.writeReg(CC1101_FREND1, 0x56); //0x56,  // FREND1        Front End RX Configuration 
cc1101.writeReg(CC1101_FREND0, 0x10); //0x10,  // FREND0        Front End TX Configuration
cc1101.writeReg(CC1101_MCSM0, 0x18); //0x18,  // MCSM0         Main Radio Control State Machine Configuration - PO timeout: 64(149-155us) - Auto calibrate from idle to rx/tx
cc1101.writeReg(CC1101_FOCCFG, 0x16); //0x16,  // FOCCFG        Frequency Offset Compensation Configuration   
cc1101.writeReg(CC1101_BSCFG, 0x6c); //0x6C,  // BSCFG         Bit Synchronization Configuration
cc1101.writeReg(CC1101_AGCCTRL2, 0x03); //0x03,  // AGCCTRL2      AGC Control - target amplitude: 33dB - Maximum possible LNA + LNA 2 gain - All gain settings can be used
cc1101.writeReg(CC1101_AGCCTRL1, 0x40); //0x40,  // AGCCTRL1      AGC Control - LNA gain decreased first
cc1101.writeReg(CC1101_AGCCTRL0, 0x91); //0x91,  // AGCCTRL0      AGC Control - Medium hysterisis - Filter Samples: 16 - Normal AGC operation 
cc1101.writeReg(CC1101_FSCAL3, 0xe9); //0xE9,  // FSCAL3        Frequency Synthesizer Calibration   
cc1101.writeReg(CC1101_FSCAL2, 0x2a); //0x2A,  // FSCAL2        Frequency Synthesizer Calibration
cc1101.writeReg(CC1101_FSCAL1, 0x00); //0x00,  // FSCAL1        Frequency Synthesizer Calibration
cc1101.writeReg(CC1101_FSCAL0, 0x1f); //0x1F,  // FSCAL0        Frequency Synthesizer Calibration
cc1101.writeReg(CC1101_FSTEST, 0x59); //0x59,  // FSTEST        Frequency Synthesizer Calibration Control
cc1101.writeReg(CC1101_TEST2, 0x88); //0x88,  // TEST2         Various Test Settings
cc1101.writeReg(CC1101_TEST1, 0x31); //0x31,  // TEST1         Various Test Settings
cc1101.writeReg(CC1101_TEST0, 0x09); //0x09,  // TEST0         Various Test Settings
cc1101.writeReg(CC1101_FIFOTHR, 0x07); //0x07,  // FIFOTHR       RX FIFO and TX FIFO Thresholds - Bytes in TX FIFO:33 - Bytes in RX FIFO:32
cc1101.writeReg(CC1101_IOCFG2, 0x06); //0x06,  // IOCFG2        GDO2 Output Pin Configuration - Sync word received/sent - end of packet
cc1101.writeReg(CC1101_PKTCTRL1, 0x04); //0x04,  // PKTCTRL1      Packet Automation Control - No address check - Automatic flush of RX FIFO is disable - sync word is always accepted
cc1101.writeReg(CC1101_PKTCTRL0, 0x05); //0x05,  // PKTCTRL0      Packet Automation Control - whitening is off - RX/TX data normal mode - CRC calculation in TX and CRC check in RX - Variable packet length
cc1101.writeReg(CC1101_ADDR, 0x00); //0x00,  // ADDR          Device Address 
cc1101.writeReg(CC1101_PKTLEN, 0xff); //0xFF,  // PKTLEN        Packet Length
cc1101.writeReg(CC1101_MCSM1, 0x3f); //0x3F,  // MCSM1         Main Radio Control State Machine Configuration
// 
cc1101.writeReg(CC1101_PATABLE, paTable[0]);

}
/**
* The setup method gets called on start of the system.
*/
void setup()
{
  Serial.begin(38400);
  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();
  config();
  /*
  b=cc1101.readReg(CC1101_FREQ0, CC1101_CONFIG_REGISTER);
  Serial.println(b);
  b=cc1101.readReg(CC1101_FREQ1, CC1101_CONFIG_REGISTER);
  Serial.println(b);  
  b=cc1101.readReg(CC1101_FREQ2, CC1101_CONFIG_REGISTER);
  Serial.println(b);
  */
  //cc1101.setCarrierFreq(CFREQ_433);
  cc1101.setTxState();
  Serial.println("device initialized");
  //Serial.println("done");
}

/**
* The loop method gets called on and on after the start of the system.
*/
void loop()
{
  Serial.println("loop...");
  
  CCPACKET data;
  data.length=1;
  byte blinkCount=counter++;
  data.data[0]=blinkCount;
  
  if(cc1101.sendData(data)){
    Serial.print("sent ok :)");
    Serial.println(blinkCount);
    for(int j=0; j<blinkCount; j++){
      blinker();
    }
  }else{
    Serial.print("sent failed :(");
    Serial.println(blinkCount);    
    blinker();
    blinker();
  }  
  Serial.println("loop done");    
  delay(1000);
}