From 3818e75a05dbd45bb01135be76bfe2ad28490190 Mon Sep 17 00:00:00 2001 From: SV-Zanshin Date: Sat, 30 Jun 2018 07:37:56 +0100 Subject: [PATCH] Added speed selection to I2C Issue #3 fixed --- src/MB85_FRAM.cpp | 3 ++- src/MB85_FRAM.h | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/MB85_FRAM.cpp b/src/MB85_FRAM.cpp index f39a10d..d01d311 100644 --- a/src/MB85_FRAM.cpp +++ b/src/MB85_FRAM.cpp @@ -23,8 +23,9 @@ uint32_t MB85_FRAM_Class::totalBytes() {return _TotalMemory;} // ** to 0xFF then we know we've had a wrap-around and have identified the chip, otherwise we repeat the procedure ** ** for the next possible memory size address and so on. ** *******************************************************************************************************************/ -uint8_t MB85_FRAM_Class::begin() { // Find I2C device // +uint8_t MB85_FRAM_Class::begin(const uint16_t i2cSpeed) { // Find I2C device // Wire.begin(); // Start I2C as master device // + Wire.setClock(i2cSpeed); // Set the I2C bus speed // for(uint8_t i=MB85_MIN_ADDRESS;i 32 bytes, optimized memory use ** @@ -48,8 +49,12 @@ /***************************************************************************************************************** ** Declare constants used in the class ** *****************************************************************************************************************/ - const uint8_t MB85_MIN_ADDRESS = 0x50; // Minimum FRAM address // - const uint8_t MB85_MAX_DEVICES = 8; // Maximum number of FRAM devices // + const uint16_t I2C_STANDARD_MODE = 100000; // Default normal I2C comms speed // + const uint16_t I2C_FAST_MODE = 400000; // Fast mode // + const uint16_t I2C_FAST_MODE_PLUS_MODE = 1000000; // Really fast mode // + const uint16_t I2C_HIGH_SPEED_MODE = 3400000; // Turbo mode // + const uint8_t MB85_MIN_ADDRESS = 0x50; // Minimum FRAM address // + const uint8_t MB85_MAX_DEVICES = 8; // Maximum number of FRAM devices // /***************************************************************************************************************** ** Main MB85_FRAM class for the temperature / humidity / pressure sensor ** @@ -58,7 +63,7 @@ public: // Publicly visible methods // MB85_FRAM_Class(); // Class constructor // ~MB85_FRAM_Class(); // Class destructor // - uint8_t begin(); // Start using I2C Communications // + uint8_t begin(const uint16_t i2cSpeed = I2C_STANDARD_MODE); // Start using I2C Communications // uint32_t totalBytes(); // Return the total memory available// uint32_t memSize(const uint8_t memNumber); // Return memory size in bytes // /*************************************************************************************************************