Skip to content

Commit

Permalink
Added speed selection to I2C
Browse files Browse the repository at this point in the history
Issue #3  fixed
  • Loading branch information
SV-Zanshin authored and SV-Zanshin committed Jun 30, 2018
1 parent bdac81e commit 3818e75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/MB85_FRAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MB85_MIN_ADDRESS+8;i++) { // loop all possible addresses //
Wire.beginTransmission(i); // Check current address for device //
if (Wire.endTransmission()==0) { // If no error we have a device //
Expand Down
11 changes: 8 additions & 3 deletions src/MB85_FRAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
** **
** Vers. Date Developer Comments **
** ====== ========== ============================= ============================================================== **
** 1.0.4 2018-06-29 https://github.com/SV-Zanshin Issue #3 added support for faster I2C bus speeds **
** 1.0.2a 2017-09-06 https://github.com/SV-Zanshin Added fillMemory() function as a template **
** 1.0.1 2017-09-06 https://github.com/SV-Zanshin Completed testing for large structures **
** 1.0.1b 2017-09-06 https://github.com/SV-Zanshin Allow structures > 32 bytes, optimized memory use **
Expand All @@ -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 **
Expand All @@ -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 //
/*************************************************************************************************************
Expand Down

0 comments on commit 3818e75

Please sign in to comment.