SmartRC-CC1101-Driver-Lib icon indicating copy to clipboard operation
SmartRC-CC1101-Driver-Lib copied to clipboard

Error in all examples!

Open frspp opened this issue 1 year ago • 1 comments

One need first define the settings and only after that try getCC1101(), not the other way around. Examples does not work because they have it the wrong way around around.

Correct way:

void setup() {
  Serial.begin(9600);

  ELECHOUSE_cc1101.setSpiPin(18, 19, 23, 17); // Must be BEFORE Init()!
  ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
  ELECHOUSE_cc1101.setGDO0(32); // set lib internal gdo pin (gdo0). Gdo2 not use for this example.
  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.9); // 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(0);  // 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.

  if (ELECHOUSE_cc1101.getCC1101()) { // Check the CC1101 Spi connection.
    Serial.println("CC1101: Connection ok.");
  } 
  else {
    Serial.println("CC1101: Connection error!");
  }

  Serial.println("CC1101: Rx mode started.");
}

frspp avatar Apr 06 '23 12:04 frspp

This does not help when using "GD-free" communication. gettCC1101() just reads register 0x31 (CC1101_VERSION according to the header file). When a chip is connected, this returns for me the value 0x04, without chip, returns 0xFF - The library checks for a value >0, so this is probably the problem. I'd guess reading from a non-existing register on SPI will just return something with all bits set. The result is independent from whether or not I initialize the chip first. Thus, the function should better read

bool ELECHOUSE_CC1101::getCC1101(void) {
	setSpi();
// Assuming only Version 4 is around...
	if (SpiReadStatus(CC1101_VERSION) == 0x04) {
		return 1;
	} else {
		return 0;
	}
}

This check is not very elaborate and could be true for many SPI devices, though.

angrest avatar Dec 30 '23 17:12 angrest