Using Sensirion SHT-11
Rsadeika
Posts: 3,837
I am trying to create a program/driver to read and display the data from the SHT-11 chip. I ran into a problem, I am not sure how to do the conversion of the raw data to a readable Celsius value. The program below compiles, and I get some values, but it is not showing the correct Celsius value. Has anybody done this already, and can show me the way?
Thanks
Ray
Thanks
Ray
/** * @file Sensi_sht11.c * This is the main Sensi_sht11 program start point. */ #include <propeller.h> #define Dpin 0 #define Cpin 1 int Sendcommand(Cmd) { int32_t result = 0; DIRA &= ~(1<<Dpin); OUTA &= ~(1<<Cpin); OUTA = ((OUTA & (~(1 << Cpin))) | (1 << Cpin)); OUTA &= ~(1<<Dpin); DIRA = ((DIRA & (~(1 << Dpin))) | (1 << Dpin)); OUTA &= ~(1<<Cpin); OUTA = ((OUTA & (~(1 << Cpin))) | (1 << Cpin)); DIRA &= ~(1<<Dpin); OUTA &= ~(1<<Cpin); return Writebyte(Cmd); } int Writebyte(Value) { int result = 0; DIRA = ((DIRA & (~(1 << Dpin))) | (1 << Dpin)); { int _idx__0044; _idx__0044 = 8; do { OUTA = ((OUTA & (~(1 << Dpin)) | ((Value >> 7) & 0x1) << Dpin)); Value = (Value << 1); OUTA ^= (1<<Cpin); OUTA ^= (1<<Cpin); _idx__0044 = (_idx__0044 + -1); } while (_idx__0044 >= 1); } DIRA &= ~(1<<Dpin); result = ((INA >> Dpin) & 0x1); OUTA ^= (1<<Cpin); OUTA ^= (1<<Cpin); return result; } int Readtemperature(void) { int Ack; int result = 0; Ack = Sendcommand(3); // SensirionSpin_Wait(); return Readword(); } int Readword(void) { int result = 0; return ((Readbyte(0) << 8) + Readbyte(1)); } int Readbyte( Ack) { int result = 0; DIRA &= ~(1<<Dpin); { int _idx__0043; _idx__0043 = 8; do { result = ((result << 1) | ((INA >> Dpin) & 0x1)); OUTA ^= (1<<Cpin); OUTA ^= (1<<Cpin); _idx__0043 = (_idx__0043 + -1); } while (_idx__0043 >= 1); } DIRA = ((DIRA & (~(1 << Dpin))) | (1 << Dpin)); OUTA = ((OUTA & (~(1 << Dpin))) | ((Ack & 0x1) << Dpin)); OUTA ^= (1<<Cpin); OUTA ^= (1<<Cpin); DIRA &= ~(1<<Dpin); return result; } int celsius(t) { int ctemp = -39.66 + (0.01 * t); return ctemp; } /** * Main program function. */ int main(void) { float rawTemp; float tempC; waitcnt(CLKFREQ + CNT); rawTemp = Readtemperature(); tempC = celsius(rawTemp); printf("%f", rawTemp); printf(" %f", tempC); return 0; }
Comments
I made a Spin version using the Sensirion, and XBee modules, which runs as expected. I also did a spin2cpp, of the Spin versions, both C and C++ versions, the C version would not compile, using SimpleIDE, was complaining about "_main". The C++ version compiled, but was producing the wrong values for the readings.
So, I decided to use the individual functions that got produced in the spin2cpp conversion which is what is shown in the OP. At this point I am not sure what the next step should be.
After looking at the Sendcommand() and Writebyte() functions, I do not know how to verify that they are working correctly, I am at a loss on this one. I think some of the C experts might have to come up with a driver for the Sensirion module, but I guess everybody is very busy doing more important things.
Ray
Massimo