Skip to content

Commit

Permalink
Added setting I2C bus speed
Browse files Browse the repository at this point in the history
Issue #3
  • Loading branch information
SV-Zanshin authored and SV-Zanshin committed Jun 30, 2018
1 parent 0265ba6 commit 6b4ed0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/DS3231M.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ DS3231M_Class::~DS3231M_Class() {} //
** Method begin starts I2C communications with the device, using a default address if one is not specified and **
** return true if the device has been detected and false if it was not **
*******************************************************************************************************************/
bool DS3231M_Class::begin() { // Start I2C communications //
bool DS3231M_Class::begin(const uint16_t i2cSpeed) { // Start I2C communications //
Wire.begin(); // Start I2C as master device //
Wire.setClock(i2cSpeed); // Set I2C clock speed //
Wire.beginTransmission(DS3231M_ADDRESS); // Address the DS3231M //
uint8_t errorCode = Wire.endTransmission(); // See if there's a device present //
if (errorCode == 0) { // If we have a DS3231M //
Expand Down
5 changes: 4 additions & 1 deletion src/DS3231M.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
** **
** Vers. Date Developer Comments **
** ====== ========== ================================= ========================================================== **
** 1.0.2 2018-06-30 https://github.com/SV-Zanshin Issue #3 - Allow 400KHz I2C bus speed to be set **
** 1.0.0 2017-08-19 https://github.com/SV-Zanshin Initial release **
** 1.0.0b 2017-08-13 https://github.com/SV-Zanshin Initial coding **
** **
Expand All @@ -45,6 +46,8 @@
/*****************************************************************************************************************
** Declare constants used in the class **
*****************************************************************************************************************/
const uint16_t I2C_STANDARD_MODE = 100000; // Default normal I2C comms speed //
const uint16_t I2C_FAST_MODE = 400000; // Fast mode //
const uint32_t SECONDS_PER_DAY = 86400; // 60 secs * 60 mins * 24 hours //
const uint32_t SECONDS_FROM_1970_TO_2000 = 946684800; // //
const uint8_t DS3231M_ADDRESS = 0x68; // Fixed I2C Address for DS3231M //
Expand Down Expand Up @@ -120,7 +123,7 @@
public: // Publicly visible methods //
DS3231M_Class(); // Class constructor //
~DS3231M_Class(); // Class destructor //
bool begin(); // Start I2C Communications //
bool begin(const uint16_t i2cSpeed = I2C_STANDARD_MODE); // Start I2C Communications //
void adjust(); // Set the date and time to compile //
void adjust(const DateTime& dt); // Set the date and time //
DateTime now(); // return time //
Expand Down

0 comments on commit 6b4ed0c

Please sign in to comment.