cancel
Showing results for 
Search instead for 
Did you mean: 

Request for I2C communication support using NUCLEO-L073RZ...ㅠ_ㅠ

Damdori
Associate II

I tried to communicate using I2C, but I failed...

So, I would like to get help from those who are good at I2C communication.

The board uses NUCLEO-L073RZ, and the device to communicate with is "SHT20 (Humidity_Sensors)" of Sensirion company.

I tried to communicate using I2C function in STM CUBE MX, but the sensor seems to communicate with 13bit... MX only supports 10bit....Please help....

7 REPLIES 7
Andrew Neil
Evangelist III

"the sensor seems to communicate with 13bit... MX only supports 10bit...."

What do you mean by that?

According to the SHT20 datasheet, it uses standard 8-bit data size:

0693W00000QKdysQAD.png

KnarfB
Principal III

> but the sensor seems to communicate with 13bit

why do you think so? According to the data sheet, the sensor has a 7-bit I2C target address and normal, byte wise data transfer.

hth

KnarfB

@Damdori​ "MX only supports 10bit...."

Are you confusing data size with the addressing modes there?

0693W00000QKe8tQAD.png

Ah, I guess I misunderstood.

In fact, I don't know much about i2c communication, so I first download the example source from SENSIRION and write the program.

The example source seems to have been written as a code that measures while directly changing the registry that defines the input and output for I2C SDA and SCL pins, but it is too difficult to directly touch the registry in the HAL function...

@Damdori​ "I don't know much about i2c communication"

It is a very widely-used and well-established protocol - so plenty of resources available ;eg,

UM10204 I 2C-bus specification and user manual - https://www.nxp.com/docs/en/user-guide/UM10204.pdf

This is the Official specification of the I2C protocol by NXP - who invented it, and "own" it.

https://en.wikipedia.org/wiki/I%C2%B2C

https://i2c.info/

https://www.i2c-bus.org/

S.Ma
Principal

Some older sensirion are not 100% I2C and provide special bit bang sw I2C dur to some long clock stretch delays, probably due to slow mcu built in the sensor to convert analog to digital I2C.... check this first.

Pavel A.
Evangelist III

Unless your SHT20 is old, it supports two sets of commands. One uses SCL stretching, another does not. In the second case the device does not respond while busy. So just use the non-stretching commands and the usual HAL functions: HAL_I2C_Master_Transmit, HAL_I2C_Master_Receive etc.

Poll the device every N ms until it responds or you wait more than documented maximum (~ 100 ms, see in the data sheet)

 The I2C address is 0x80. 

// SHT20/25 commands:
typedef enum{
  SHT2x_TRIG_T_MEASUREMENT_HM = 0xE3,   // trig. temp meas. hold master
  SHT2x_TRIG_RH_MEASUREMENT_HM = 0xE5, //trig. humidity meas. hold master
  SHT2x_TRIG_T_MEASUREMENT_POLL = 0xF3, //trig. temp meas. no hold master <<<
  SHT2x_TRIG_RH_MEASUREMENT_POLL = 0xF5, //trig. humidity meas. no hold master <<<
  SHT2x_USER_REG_W = 0xE6, // writing user register
  SHT2x_USER_REG_R = 0xE7, // reading user register
  SHT2x_SOFT_RESET = 0xFE // soft reset
} eSHT2xCmd;
 
#define A_READ_TEMP_TMO   100   /* ms, max time from [DS, table 7] */
#define A_READ_RH_TMO        29     /* ms, max time from [DS, table 7] */