LSatan / SmartRC-CC1101-Driver-Lib

This driver library can be used for many libraries that use a simple RF ASK module, with the advantages of the cc1101 module. It offers many direct setting options as in SmartRF Studio and calculates settings such as MHz directly.
Other
430 stars 95 forks source link

SPI issues with Raspberry Pi Pico #134

Closed smolbun closed 1 year ago

smolbun commented 1 year ago

Only the default SPI works when using the pico ELECHOUSE_cc1101.setSpiPin(18, 16, 19, 17) , I've tried other SPI ports refering to the pinout diagram . Any idea why it doesn't work on other SPI ports?

Modified example without GDO
#include <ELECHOUSE_CC1101_SRC_DRV.h>

byte transmitt_byte[11] = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 };
char *transmitt_char = "Hello World";

void setup() {

  Serial.begin(115200);
  delay(5000);
  Serial.println("Started");
}

void loop() {
   Serial.println("void loop");

  //ELECHOUSE_cc1101.setSpiPin(13, 12, 11, 10); // UNO/nano (working)
  //ELECHOUSE_cc1101.setSpiPin(18, 16, 19, 17); // pico (working)
  ELECHOUSE_cc1101.setSpiPin(9 ,11 ,10 ,12); // pico (not working)

  while (true) {  // Check the CC1101 Spi connection.
    if (ELECHOUSE_cc1101.getCC1101()) {
      Serial.println("Connection OK");
      break;
    }

    Serial.println("Connection Error");
    delay(100);
  }

  ELECHOUSE_cc1101.Init();            // must be set to initialize the cc1101!
  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.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.
  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.
                                    // 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!
  ELECHOUSE_cc1101.setCrc(1);       // 1 = CRC calculation in TX and CRC check in RX enabled. 0 = CRC disabled for TX and RX.

  Serial.println("Tx Mode");
  //3 different methods to send data without gdo
  //When sending, we give a little time to completely transmit the message (time in millis).
  //You can shorten the time. It depends on the data rate and the packet length. Just try it out for fine tuning.

  //Transmitt "Hello World" from byte format.
  ELECHOUSE_cc1101.SendData(transmitt_byte, 11, 100);
  delay(2000);

  //Transmitt "Hello World" from char format.
  ELECHOUSE_cc1101.SendData(transmitt_char, 100);
  delay(2000);

  //Transmitt "Hello World" from char format directly.
  ELECHOUSE_cc1101.SendData("Hello World", 100);
  delay(2000);
  ELECHOUSE_cc1101.setSres();
}
smolbun commented 1 year ago

I've edited SpiStart to include support for RP2040

SPI.set...() only works for SPI0, if SPI1 is used, replace SPI. with SPI1.
void ELECHOUSE_CC1101::SpiStart(void)
{
  // initialize the SPI pins
  pinMode(SCK_PIN, OUTPUT);
  pinMode(MOSI_PIN, OUTPUT);
  pinMode(MISO_PIN, INPUT);
  pinMode(SS_PIN, OUTPUT);

  // enable SPI
  #ifdef ESP32
  SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
  #elif ARDUINO_ARCH_RP2040
  SPI.setRX(MISO_PIN);
  SPI.setCS(SS_PIN);
  SPI.setSCK(SCK_PIN);
  SPI.setTX(MOSI_PIN);
  SPI.begin();
  #else
  SPI.begin();
  #endif
}