| | |
| | | ***********************************************************************/ |
| | | #include <stdio.h> |
| | | #include <string.h> |
| | | #include "i2c.h" |
| | | #include "i2c_bitbang.h" |
| | | #include "sht20.h" |
| | | |
| | | #define CONFIG_DEBUG_SHT2X /* Enable SHT20 debug */ |
| | | //#define CONFIG_DEBUG_SHT2X /* Enable SHT20 debug */ |
| | | |
| | | #define SHT2X_CHIPADDR 0x40 /* SHT20 7-Bits Chip address */ |
| | | |
| | |
| | | float temp, rh; |
| | | int rv; |
| | | |
| | | i2c_lock(SHT2X_CHIPADDR); |
| | | |
| | | if( sht2x_softreset() < 0 ) |
| | | { |
| | | sht2x_print("SHT20 soft reset failed.\r\n"); |
| | |
| | | *humdity=rh; |
| | | |
| | | OUT: |
| | | i2c_free(); |
| | | return rv; |
| | | } |
| | | |
| | |
| | | |
| | | sht2x_print("Start soft reset sht2x\r\n"); |
| | | |
| | | rv=HAL_I2C_Master_Transmit(&hi2c1, SHT2X_CHIPADDR<<1, &command, 1, 0xFFFFFFFF); |
| | | if( rv != HAL_OK ) |
| | | rv=i2c_write(&command, 1); |
| | | if( rv ) |
| | | { |
| | | sht2x_print("SHT2X send soft reset command 0x%0x failure: rv=0x%02x\r\n", command, rv); |
| | | return -rv; |
| | |
| | | return -2; |
| | | } |
| | | |
| | | if( HAL_I2C_Master_Transmit(&hi2c1, SHT2X_CHIPADDR<<1, &command, 1, 0xFFFFFFFF) != HAL_OK ) |
| | | if( i2c_write(&command, 1) < 0 ) |
| | | { |
| | | sht2x_print("SHT2X send measure command 0x%0x failure\r\n", command); |
| | | return -3; |
| | |
| | | { |
| | | memset(buf, 0, 3); |
| | | |
| | | if( HAL_OK == HAL_I2C_Master_Receive(&hi2c1, SHT2X_CHIPADDR<<1|1, buf, 3, 0xFFFFFFFF) ) |
| | | if( !i2c_read(buf, 3) ) |
| | | { |
| | | break; |
| | | } |