- Delaying and repeating i2c operation automatically when i2c interface is busy removed. User has to deal with concurrency using semaphores.
- GPIO_ID_PIN macros removed - Soft reset mechanism of SHT3x does not work when sensor is in any measurement mode. Therefore, it does not abort initialization procedure anymore - typos - changes to use the same source code with ESP8266 (esp-open-rtos) and ESP32 (ESP-IDF)
This commit is contained in:
parent
c3ae04c93f
commit
ca0b5da905
7 changed files with 254 additions and 110 deletions
|
|
@ -2,13 +2,16 @@
|
|||
* Driver for Sensirion SHT3x digital temperature and humidity sensor
|
||||
* connected to I2C
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* This driver is for the usage with the ESP8266 and FreeRTOS (esp-open-rtos)
|
||||
* [https://github.com/SuperHouse/esp-open-rtos]. It is also working with ESP32
|
||||
* and ESP-IDF [https://github.com/espressif/esp-idf.git] as well as Linux
|
||||
* based systems using a wrapper library for ESP8266 functions.
|
||||
*
|
||||
* ----------------------------------------------------------------
|
||||
*
|
||||
* The BSD License (3-clause license)
|
||||
*
|
||||
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht
|
||||
* Copyright (c) 2017 Gunar Schorcht (https://github.com/gschorcht)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -38,23 +41,11 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Driver for Sensirion SHT3x digital temperature and humity sensor
|
||||
* connected to I2C
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sht3x.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "espressif/esp_common.h"
|
||||
#include "espressif/sdk_private.h"
|
||||
|
||||
#define SHT3x_STATUS_CMD 0xF32D
|
||||
#define SHT3x_CLEAR_STATUS_CMD 0x3041
|
||||
#define SHT3x_RESET_CMD 0x30A2
|
||||
|
|
@ -139,12 +130,10 @@ sht3x_sensor_t* sht3x_init_sensor(uint8_t bus, uint8_t addr)
|
|||
|
||||
uint16_t status;
|
||||
|
||||
// reset the sensor
|
||||
// try to reset the sensor
|
||||
if (!sht3x_reset(dev))
|
||||
{
|
||||
error_dev ("could not reset the sensor", __FUNCTION__, dev);
|
||||
free(dev);
|
||||
return NULL;
|
||||
debug_dev ("could not reset the sensor", __FUNCTION__, dev);
|
||||
}
|
||||
|
||||
// check again the status after clear status command
|
||||
|
|
@ -325,13 +314,7 @@ static bool sht3x_send_command(sht3x_sensor_t* dev, uint16_t cmd)
|
|||
|
||||
debug_dev ("send command MSB=%02x LSB=%02x", __FUNCTION__, dev, data[0], data[1]);
|
||||
|
||||
int err;
|
||||
int count = 10;
|
||||
|
||||
// in case i2c is busy, try to write up to ten ticks (normally 100 ms)
|
||||
// tested with a task that is disturbing by using i2c bus almost all the time
|
||||
while ((err=i2c_slave_write(dev->bus, dev->addr, 0, data, 2)) == -EBUSY && count--)
|
||||
vTaskDelay (1);
|
||||
int err = i2c_slave_write(dev->bus, dev->addr, 0, data, 2);
|
||||
|
||||
if (err)
|
||||
{
|
||||
|
|
@ -339,21 +322,14 @@ static bool sht3x_send_command(sht3x_sensor_t* dev, uint16_t cmd)
|
|||
error_dev ("i2c error %d on write command %02x", __FUNCTION__, dev, err, cmd);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool sht3x_read_data(sht3x_sensor_t* dev, uint8_t *data, uint32_t len)
|
||||
{
|
||||
if (!dev) return false;
|
||||
|
||||
int err;
|
||||
int count = 10;
|
||||
|
||||
// in case i2c is busy, try to read up to ten ticks (normally 100 ms)
|
||||
while ((err=i2c_slave_read(dev->bus, dev->addr, 0, data, len)) == -EBUSY && count--)
|
||||
vTaskDelay (1);
|
||||
int err = i2c_slave_read(dev->bus, dev->addr, 0, data, len);
|
||||
|
||||
if (err)
|
||||
{
|
||||
|
|
@ -368,7 +344,7 @@ static bool sht3x_read_data(sht3x_sensor_t* dev, uint8_t *data, uint32_t len)
|
|||
for (int i=0; i < len; i++)
|
||||
printf("%02x ", data[i]);
|
||||
printf("\n");
|
||||
# endif
|
||||
# endif // ifdef SHT3x_DEBUG_LEVEL_2
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue