cancel
Showing results for 
Search instead for 
Did you mean: 

please save me,,, i am writing code to sht30 sensor for i2c communication

Imhyeonu
Associate

At this point, the I2C statuses all look normal. I have written code to extract temperature and humidity data values via high-resolution single-shot mode, but the data values are not being extracted correctly. Do I need to set the high-speed mode and access write, read before entering single-shot mode? I don't know what the heck is wrong.

board:NUCLEOF303K8 / sensor: SHT30DLS, gpio / i2c source and header file is no problem / i2c = fast mode

if you help me. i'm will bless to you every every every day... 

1 ACCEPTED SOLUTION

Accepted Solutions
padawan
Senior

Second reply

in your conv you 

calc  *Temperature = -40.0f + 125.0f * ((float)tempRaw / 65535.0f);

in the datasheet it is 

padawan_0-1706708410544.png

so there is a wrong formular in your source code.

padawan

View solution in original post

3 REPLIES 3
padawan
Senior

Ok some questions:

why do you not use the HAL_I2C_Master_Transmit ans HAL_I2C_Master_Receive?

There are some "Pullups" on SDL SCL?

The first command to the Sht3xx i send is  "WriteCommand(CMD_MEAS_POLLING_H);"

By

uint8_t sht3x::WriteCommand(etCommands command)

{

etError error; // error code

HAL_StatusTypeDef _hal;

uint8_t _sbuff[2] ={0x00, 0x00}; // Array to transmit /PE

_sbuff[0] = (command >> 8);

_sbuff[1] = (command & 0xFF);

 

_hal = HAL_I2C_Master_Transmit(_i2c,_adr, _sbuff, 2,1000);

_ok = _hal;

error = (etError)_ok;

return error;

}

 

If you read from the Sensor you have to read 3 Bytes, 2 data and CRC

or 5 bytes (2 Temp 2 Hum 1 CRC).

 

 

If you look at https://www.sensirion.com/products/downloads/?category=Humidity

in section Software Sample Code SHT3x.

I change the "i2c.h" and "i2c.c" to the STM HAL.

You can first read the serialnumber before you try to read and calculate the temp.

 

HTH

padawan

 

padawan
Senior

Second reply

in your conv you 

calc  *Temperature = -40.0f + 125.0f * ((float)tempRaw / 65535.0f);

in the datasheet it is 

padawan_0-1706708410544.png

so there is a wrong formular in your source code.

padawan

Thank you for your response. I apologize for the delay in getting back to you.
The code I'm currently writing is intended to be written entirely in C, to build a foundation and avoid using the HAL library as much as possible. I changed the formula, thanks a lot!!!! 🙂