Skip to content

Commit

Permalink
I2C clock speed external to library
Browse files Browse the repository at this point in the history
Moved I2C clock speed settingoutside of the library and updated examples
  • Loading branch information
oclyke committed Oct 29, 2018
1 parent d92157d commit c42ec0c
Show file tree
Hide file tree
Showing 7 changed files with 851 additions and 919 deletions.
3 changes: 2 additions & 1 deletion examples/Example1_BasicReadings/Example1_BasicReadings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ void setup() {
SERIAL_PORT.println();

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
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
errorDecoder(mySHTC3.begin()); // To start the sensor you must call "begin()", the default settings use Wire (default Arduino I2C port)
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
SERIAL_PORT.println();

if(mySHTC3.passIDcrc) // Whenever data is received the associated checksum is calculated and verified so you can be sure the data is true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#define WIRE_PORT Wire // This allows you to choose another Wire port (as long as your board supports more than one)
#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

//#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
SHTC3 mySHTC3; // Declare an instance of the SHTC3 class

void setup() {
Expand All @@ -32,7 +32,12 @@ void setup() {
SERIAL_PORT.println();

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
errorDecoder(mySHTC3.begin(WIRE_PORT, WIRE_SPEED)); // Calling "begin()" with port and speed arguments allows you to reassign the interface to the sensor
errorDecoder(mySHTC3.begin(WIRE_PORT)); // Calling "begin()" with the port argument allows you to reassign the interface to the sensor
#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!
WIRE_PORT.setClock(WIRE_SPEED);
#else
WIRE_PORT.setClock(SHTC3_MAX_CLOCK_FREQ);
#endif
SERIAL_PORT.println();

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

0 comments on commit c42ec0c

Please sign in to comment.