From 3b1934e6683cea86be1435db86efb836105a0e40 Mon Sep 17 00:00:00 2001 From: FUEL4EP Date: Tue, 26 Mar 2024 10:29:25 +0100 Subject: [PATCH] added Fujitsu MB85RS4MT FRAM; added sleep mode --- Adafruit_FRAM_SPI.cpp | 37 +++++++++++++++++++++++++++++++++++++ Adafruit_FRAM_SPI.h | 18 +++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Adafruit_FRAM_SPI.cpp b/Adafruit_FRAM_SPI.cpp index 9284998..4622fc2 100644 --- a/Adafruit_FRAM_SPI.cpp +++ b/Adafruit_FRAM_SPI.cpp @@ -46,6 +46,7 @@ const struct { {0x04, 0x2503, 32 * 1024UL}, // MB85RS256TY {0x04, 0x2703, 128 * 1024UL}, // MB85RS1MT {0x04, 0x4803, 256 * 1024UL}, // MB85RS2MTA + {0x04, 0x2803, 256 * 1024UL}, // MB85RS2MT {0x04, 0x4903, 512 * 1024UL}, // MB85RS4MT // Cypress @@ -343,3 +344,39 @@ bool Adafruit_FRAM_SPI::setStatusRegister(uint8_t value) { void Adafruit_FRAM_SPI::setAddressSize(uint8_t nAddressSize) { _nAddressSizeBytes = nAddressSize; } + +/*! + * @brief Enters the FRAM's low power sleep mode + * @return true if successful + */ +// WARNING: this method has not yet been validated +bool Adafruit_FRAM_SPI::enter_low_power_mode(void) { + uint8_t cmd; + + cmd = OPCODE_SLEEP; + + return spi_dev->write(&cmd, 1); +} + + +/*! + * @brief exits the FRAM's low power sleep mode + * @return true if successful + */ +// WARNING: this method has not yet been validated +bool Adafruit_FRAM_SPI::exit_low_power_mode(void) { + uint8_t cmd; + + // Returning to an normal operation from the SLEEP mode is carried out after tREC (Max 400 μs) + // time from the falling edge of CS + spi_dev->beginTransactionWithAssertingCS(); + delayMicroseconds(300); + // It is possible to return CS to H level before tREC time. However, it + // is prohibited to bring down CS to L level again during tREC period. + spi_dev->endTransactionWithDeassertingCS(); + delayMicroseconds(100); + + return spi_dev->write(&cmd, 1); +} + + diff --git a/Adafruit_FRAM_SPI.h b/Adafruit_FRAM_SPI.h index 3baf249..214adae 100644 --- a/Adafruit_FRAM_SPI.h +++ b/Adafruit_FRAM_SPI.h @@ -18,6 +18,7 @@ * * BSD license, all text above must be included in any redistribution */ + #ifndef _ADAFRUIT_FRAM_SPI_H_ #define _ADAFRUIT_FRAM_SPI_H_ @@ -27,13 +28,14 @@ /** Operation Codes **/ typedef enum opcodes_e { - OPCODE_WREN = 0b0110, /* Write Enable Latch */ - OPCODE_WRDI = 0b0100, /* Reset Write Enable Latch */ - OPCODE_RDSR = 0b0101, /* Read Status Register */ - OPCODE_WRSR = 0b0001, /* Write Status Register */ - OPCODE_READ = 0b0011, /* Read Memory */ - OPCODE_WRITE = 0b0010, /* Write Memory */ - OPCODE_RDID = 0b10011111 /* Read Device ID */ + OPCODE_WREN = 0b0110, /* Write Enable Latch */ + OPCODE_WRDI = 0b0100, /* Reset Write Enable Latch */ + OPCODE_RDSR = 0b0101, /* Read Status Register */ + OPCODE_WRSR = 0b0001, /* Write Status Register */ + OPCODE_READ = 0b0011, /* Read Memory */ + OPCODE_WRITE = 0b0010, /* Write Memory */ + OPCODE_RDID = 0b10011111, /* Read Device ID */ + OPCODE_SLEEP = 0b10111001 /* Sleep Mode */ // added by FUEL4EP } opcodes_t; /*! @@ -56,6 +58,8 @@ class Adafruit_FRAM_SPI { uint8_t getStatusRegister(void); bool setStatusRegister(uint8_t value); void setAddressSize(uint8_t nAddressSize); + bool enter_low_power_mode(void); // added by FUEL4EP + bool exit_low_power_mode(void); // added by FUEL4EP private: Adafruit_SPIDevice *spi_dev = NULL;