Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example_2threads_RAK811
Revision 2:c84a60326ecf, committed 2017-09-11
- Comitter:
- andcor02
- Date:
- Mon Sep 11 13:51:03 2017 +0000
- Parent:
- 1:756e26f0b067
- Child:
- 3:861437b6816f
- Commit message:
- Working with mbed os 5.5
Changed in this revision
| Sht31.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Sht31.cpp Thu Jul 21 15:31:08 2016 +0000
+++ b/Sht31.cpp Mon Sep 11 13:51:03 2017 +0000
@@ -18,8 +18,7 @@
#include "mbed.h"
Sht31::Sht31(PinName sda, PinName scl) : _i2c(sda, scl) {
- _i2caddr = 0x44;
- printf("\r\n");
+ _i2caddr = (0x44 << 1);
reset();
readStatus();
}
@@ -42,26 +41,20 @@
uint16_t Sht31::readStatus(void) {
writeCommand(SHT31_READSTATUS);
char val[1];
- _i2c.start();
_i2c.read(_i2caddr, val, 1);
- _i2c.stop();
uint16_t stat = val[0];
stat <<= 8;
- _i2c.start();
_i2c.read(_i2caddr, val, 1);
- _i2c.stop();
stat |= val[0];
- printf("0x%X\r\n", stat);
+ // printf("0x%X\r\n", stat);
return stat;
}
void Sht31::writeCommand(uint16_t cmd) {
char buf[2];
- _i2c.start();
buf[0] = (cmd >> 8);
buf[1] = (cmd & 0xFF);
_i2c.write(_i2caddr, buf, 2);
- _i2c.stop();
}
bool Sht31::readTempHum(void) {
@@ -70,12 +63,8 @@
writeCommand(SHT31_MEAS_HIGHREP);
wait_ms(500);
- _i2c.start();
_i2c.read(_i2caddr, readbuffer, 6);
- _i2c.stop();
- for (uint8_t i = 0; i < 6; i++) {
- printf("0x%Xd\r\n", readbuffer[i]);
- }
+
uint16_t ST, SRH;
ST = readbuffer[0];
ST <<= 8;
@@ -93,14 +82,12 @@
return false;
}
- printf("ST = %d\r\n", ST);
double stemp = ST;
stemp *= 175;
stemp /= 0xffff;
stemp = -45 + stemp;
temp = stemp;
- printf("SRH = %d\r\n", SRH);
double shum = SRH;
shum *= 100;
shum /= 0xFFFF;