Skip to main content
Damdori
Associate II
July 7, 2022
Question

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

  • July 7, 2022
  • 7 replies
  • 1998 views

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....

This topic has been closed for replies.

7 replies

Andrew Neil
Super User
July 7, 2022

"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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
July 7, 2022

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

Are you confusing data size with the addressing modes there?

0693W00000QKe8tQAD.png

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Damdori
DamdoriAuthor
Associate II
July 8, 2022

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...

KnarfB
Super User
July 7, 2022

> 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

S.Ma
Principal
July 8, 2022

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.
July 8, 2022

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] */