WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c42ec0c

Browse files
committed
I2C clock speed external to library
Moved I2C clock speed settingoutside of the library and updated examples
1 parent d92157d commit c42ec0c

File tree

7 files changed

+851
-919
lines changed

7 files changed

+851
-919
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ void setup() {
2929
SERIAL_PORT.println();
3030

3131
SERIAL_PORT.print("Beginning sensor. Result = "); // Most SHTC3 functions return a variable of the type "SHTC3_Status_TypeDef" to indicate the status of their execution
32-
errorDecoder(mySHTC3.begin()); // To start the sensor you must call "begin()", the defualt settings use Wire (default Arduino I2C port) at 400 kHz clock speed
32+
errorDecoder(mySHTC3.begin()); // To start the sensor you must call "begin()", the default settings use Wire (default Arduino I2C port)
33+
Wire.setClock(400000); // The sensor is listed to work up to 1 MHz I2C speed, but the I2C clock speed is global for all sensors on that bus so using 400kHz or 100kHz is recommended
3334
SERIAL_PORT.println();
3435

3536
if(mySHTC3.passIDcrc) // Whenever data is received the associated checksum is calculated and verified so you can be sure the data is true

examples/Example2_ChangingOptions/Example2_ChangingOptions.ino

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#define WIRE_PORT Wire // This allows you to choose another Wire port (as long as your board supports more than one)
2424
#define WIRE_SPEED 800000 // 800 kHz is the fastest speed that worked on the Uno, but the sensor is rated for up to 1 MHz
25-
25+
//#define WIRE_SPEED SHTC3_MAX_CLOCK_FREQ // This is just to show you that there is a defined constant for the maximum rated speed. You might be able to use this speed depending on the microcontroller you use
2626
SHTC3 mySHTC3; // Declare an instance of the SHTC3 class
2727

2828
void setup() {
@@ -32,7 +32,12 @@ void setup() {
3232
SERIAL_PORT.println();
3333

3434
SERIAL_PORT.print("Beginning sensor. Result = "); // Most SHTC3 functions return a variable of the type "SHTC3_Status_TypeDef" to indicate the status of their execution
35-
errorDecoder(mySHTC3.begin(WIRE_PORT, WIRE_SPEED)); // Calling "begin()" with port and speed arguments allows you to reassign the interface to the sensor
35+
errorDecoder(mySHTC3.begin(WIRE_PORT)); // Calling "begin()" with the port argument allows you to reassign the interface to the sensor
36+
#if(WIRE_SPEED <= SHTC3_MAX_CLOCK_FREQ) // You can boost the speed of the I2C interface, but keep in mind that other I2C sensors may not support as high a speed!
37+
WIRE_PORT.setClock(WIRE_SPEED);
38+
#else
39+
WIRE_PORT.setClock(SHTC3_MAX_CLOCK_FREQ);
40+
#endif
3641
SERIAL_PORT.println();
3742

3843
if(mySHTC3.passIDcrc) // Whenever data is received the associated checksum is calculated and verified so you can be sure the data is true

0 commit comments

Comments
 (0)