mattairtech / EEPROM_CAT25

Driver for On Semiconductor CAT25 SPI EEPROM chips for AVR, SAM3X (Due), and SAM M0+ (SAMD, SAML, SAMC) microcontrollers on the Arduino platform.
6 stars 4 forks source link

Is it possible to use EEPROM_CAT25 with an ESP32? #7

Closed scoover closed 2 years ago

scoover commented 3 years ago

I'm successfully running EEPROM_CAT25 on a SAMD M0 microcontroller. I'm trying to port that code to an Adafruit ESP32.

The ESP32 microcontroller is not explicitly supported by this library and I get the error:

WARNING: library EEPROM_CAT25 claims to run on avr, sam, samd architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s).
In file included from /Users/randy/Dropbox/Documents/Carbonator-ESP32/Carbonator-ESP32.ino:23:0:
/Volumes/Commando/Users/randy/Documents/Arduino/libraries/EEPROM_CAT25/src/EEPROM_CAT25.h:33:59: error: operator '||' has no right operand
 #if (!defined(SPI_HAS_TRANSACTION) || SPI_HAS_TRANSACTION == 0)

Is it possible to modify this library to work with the ESP32? Or is there another similar library that is compatible with the ESP32 and interfaces with the CAT25320?

Thanks, Randy

scoover commented 3 years ago

I think I figured this out, I'm just not totally comfortable with the solution.

The issue is that the ESP32's SPI library defines SPI_HAS TRANSACTION like this: #define SPI_HAS_TRANSACTION

When the empty definition for SPI_HAS_TRANSACTION is plugged into some preprocessor directives in EEPROM_CAT25.h, the second test (... || SPI_HAS_TRANSACTION == 0) renders as || == 0:

#if (!defined(SPI_HAS_TRANSACTION) || SPI_HAS_TRANSACTION == 0)
#error "EEPROM_CAT25 library requires SPI library transaction support (SPI_HAS_TRANSACTION = 1)"
#endif

My solution is just to comment these three lines out of EEPROM_CAT25.h. The library seems to function on my ESP32 now. Is there any reason not to resolve the problem in this way?

Thanks, Randy

crystalcave commented 3 years ago

I've same problem with Arduino Nano 33 IOT while it is stated that it supports SAMD processors, I will try the same approach ...

crystalcave commented 3 years ago

Same approach, same resulting, I will do a series of tests to understand if there are pitfalls around the corner ...