veonik / arduino-cc1101

Arduino library for interfacing with CC1101 transceivers.
GNU Lesser General Public License v3.0
156 stars 52 forks source link

ESP32 compatibility #7

Closed wilhelmzeuschner closed 6 years ago

wilhelmzeuschner commented 6 years ago

I'd love to use this library with an ESP32 board but it does not work. I have used the SPI pins:

//SPI.begin(SCK, MISO, MOSI, SS);
SPI.begin(18, 19, 23, 5);

Unfortunately this doesn't work properly:

CC1101_PARTNUM 0
CC1101_VERSION 0
CC1101_MARCSTATE 0

I get this same result when I use an Arduino Nano (with unmodified library) and simply "unplug" the module. Communication between two Nanos works fine.

The ESP32 handles interrupts a bit differently compared to an Arduino Nano, I think that I have adopted my code accordingly. ESP32_CC1101.zip

pinoutdoit32devkitv1

wilhelmzeuschner commented 6 years ago

I figured out the issue:

The Slave Select pin is not declared as an output and thus no digitalWrite()-operations work properly.

void setup() {
    pinMode(SS, OUTPUT);   //Default is pin 5, can be changed
...
}

SS not declared as output (you can see some crosstalk from the SPI communication but no real activity on that pin): ds1z_quickprint15

SS declared as output: ds1z_quickprint13 ds1z_quickprint14

wilhelmzeuschner commented 6 years ago

Created a pull-request: #8

tyler-sommer commented 6 years ago

Excellent stuff, thanks! Do you think SS should be declared as an output for nano as well?

I'll let you close this when you deem all the issues are worked out. Cheers

wilhelmzeuschner commented 6 years ago

At first, when I figured out the solution for the ESP32 if left out #ifdef ESP32 ... Later when I recompiled the code for an Arduino Nano it did not work. My guess is that the different platforms handle the SPI-interfacing differently.

I'll close this issue now, since this compatibility issue has been resolved. I thank you too for your great work!

Maybe you could improve the design of the example sketch a little bit:

#if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
#define CC1101Interrupt 4 // Pin 19
#define CC1101_GDO0 19
#elif defined(__MK64FX512__)
// Teensy 3.5
#define CC1101Interrupt 9 // Pin 9
#define CC1101_GDO0 9
#else
#define CC1101Interrupt 0 // Pin 2
#define CC1101_GDO0 2
#endif

CC1101_GDO0 is also defined in cc1101.h but the definition gets overridden by the example. Also you could add #ifdef ESP32 ... (and point out that many different pins can be used '*') to the example, depending on you want to handle things.

'*' It's best to choose a pin >= 34, since those are only input.