Skip to content

Commit 3818e75

Browse files
SV-ZanshinSV-Zanshin
SV-Zanshin
authored and
SV-Zanshin
committed
Added speed selection to I2C
Issue #3 fixed
1 parent bdac81e commit 3818e75

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/MB85_FRAM.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ uint32_t MB85_FRAM_Class::totalBytes() {return _TotalMemory;} //
2323
** to 0xFF then we know we've had a wrap-around and have identified the chip, otherwise we repeat the procedure **
2424
** for the next possible memory size address and so on. **
2525
*******************************************************************************************************************/
26-
uint8_t MB85_FRAM_Class::begin() { // Find I2C device //
26+
uint8_t MB85_FRAM_Class::begin(const uint16_t i2cSpeed) { // Find I2C device //
2727
Wire.begin(); // Start I2C as master device //
28+
Wire.setClock(i2cSpeed); // Set the I2C bus speed //
2829
for(uint8_t i=MB85_MIN_ADDRESS;i<MB85_MIN_ADDRESS+8;i++) { // loop all possible addresses //
2930
Wire.beginTransmission(i); // Check current address for device //
3031
if (Wire.endTransmission()==0) { // If no error we have a device //

src/MB85_FRAM.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
** **
3535
** Vers. Date Developer Comments **
3636
** ====== ========== ============================= ============================================================== **
37+
** 1.0.4 2018-06-29 https://github.com/SV-Zanshin Issue #3 added support for faster I2C bus speeds **
3738
** 1.0.2a 2017-09-06 https://github.com/SV-Zanshin Added fillMemory() function as a template **
3839
** 1.0.1 2017-09-06 https://github.com/SV-Zanshin Completed testing for large structures **
3940
** 1.0.1b 2017-09-06 https://github.com/SV-Zanshin Allow structures > 32 bytes, optimized memory use **
@@ -48,8 +49,12 @@
4849
/*****************************************************************************************************************
4950
** Declare constants used in the class **
5051
*****************************************************************************************************************/
51-
const uint8_t MB85_MIN_ADDRESS = 0x50; // Minimum FRAM address //
52-
const uint8_t MB85_MAX_DEVICES = 8; // Maximum number of FRAM devices //
52+
const uint16_t I2C_STANDARD_MODE = 100000; // Default normal I2C comms speed //
53+
const uint16_t I2C_FAST_MODE = 400000; // Fast mode //
54+
const uint16_t I2C_FAST_MODE_PLUS_MODE = 1000000; // Really fast mode //
55+
const uint16_t I2C_HIGH_SPEED_MODE = 3400000; // Turbo mode //
56+
const uint8_t MB85_MIN_ADDRESS = 0x50; // Minimum FRAM address //
57+
const uint8_t MB85_MAX_DEVICES = 8; // Maximum number of FRAM devices //
5358

5459
/*****************************************************************************************************************
5560
** Main MB85_FRAM class for the temperature / humidity / pressure sensor **
@@ -58,7 +63,7 @@
5863
public: // Publicly visible methods //
5964
MB85_FRAM_Class(); // Class constructor //
6065
~MB85_FRAM_Class(); // Class destructor //
61-
uint8_t begin(); // Start using I2C Communications //
66+
uint8_t begin(const uint16_t i2cSpeed = I2C_STANDARD_MODE); // Start using I2C Communications //
6267
uint32_t totalBytes(); // Return the total memory available//
6368
uint32_t memSize(const uint8_t memNumber); // Return memory size in bytes //
6469
/*************************************************************************************************************

0 commit comments

Comments
 (0)