mirror of
https://github.com/boschsensortec/BME280_SensorAPI.git
synced 2024-10-05 20:47:48 -04:00
Added a wait until the NVM copy was complete.
This commit is contained in:
parent
47596cdf7f
commit
bdf4e573cb
15
README.md
15
README.md
@ -7,9 +7,9 @@ The sensor driver package includes bme280.c, bme280.h and bme280_defs.h files.
|
|||||||
## Version
|
## Version
|
||||||
File | Version | Date
|
File | Version | Date
|
||||||
--------------|---------|------------
|
--------------|---------|------------
|
||||||
bme280.c | 3.3.6 | 08 Mar 2019
|
bme280.c | 3.3.7 | 26 Aug 2019
|
||||||
bme280.h | 3.3.6 | 08 Mar 2019
|
bme280.h | 3.3.7 | 26 Aug 2019
|
||||||
bme280_defs.h | 3.3.6 | 08 Mar 2019
|
bme280_defs.h | 3.3.7 | 26 Aug 2019
|
||||||
|
|
||||||
## Integration details
|
## Integration details
|
||||||
* Integrate bme280.h, bme280_defs.h and bme280.c file in to the project.
|
* Integrate bme280.h, bme280_defs.h and bme280.c file in to the project.
|
||||||
@ -280,19 +280,16 @@ int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint1
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Data on the bus should be like
|
* Data on the bus should be like
|
||||||
* |------------+----------------------|
|
* |------------+---------------------|
|
||||||
* | I2C action | Data |
|
* | I2C action | Data |
|
||||||
* |------------+----------------------|
|
* |------------+---------------------|
|
||||||
* | Start | - |
|
* | Start | - |
|
||||||
* | Write | (reg_addr) |
|
* | Write | (reg_addr) |
|
||||||
* | Write | (reg_data[0]) |
|
* | Write | (reg_data[0]) |
|
||||||
* | Write | (reg_addr + 1) |
|
|
||||||
* | Write | (reg_data[1]) |
|
|
||||||
* | Write | (....) |
|
* | Write | (....) |
|
||||||
* | Write | (reg_addr + len - 1) |
|
|
||||||
* | Write | (reg_data[len - 1]) |
|
* | Write | (reg_data[len - 1]) |
|
||||||
* | Stop | - |
|
* | Stop | - |
|
||||||
* |------------+----------------------|
|
* |------------+---------------------|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return rslt;
|
return rslt;
|
||||||
|
24
bme280.c
24
bme280.c
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* File bme280.c
|
* File bme280.c
|
||||||
* Date 08 Mar 2019
|
* Date 26 Aug 2019
|
||||||
* Version 3.3.6
|
* Version 3.3.7
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -632,9 +632,11 @@ int8_t bme280_soft_reset(const struct bme280_dev *dev)
|
|||||||
{
|
{
|
||||||
int8_t rslt;
|
int8_t rslt;
|
||||||
uint8_t reg_addr = BME280_RESET_ADDR;
|
uint8_t reg_addr = BME280_RESET_ADDR;
|
||||||
|
uint8_t status_reg = 0;
|
||||||
|
uint8_t try_run = 5;
|
||||||
|
|
||||||
/* 0xB6 is the soft reset command */
|
/* 0xB6 is the soft reset command */
|
||||||
uint8_t soft_rst_cmd = 0xB6;
|
uint8_t soft_rst_cmd = BME280_SOFT_RESET_COMMAND;
|
||||||
|
|
||||||
/* Check for null pointer in the device structure*/
|
/* Check for null pointer in the device structure*/
|
||||||
rslt = null_ptr_check(dev);
|
rslt = null_ptr_check(dev);
|
||||||
@ -645,8 +647,22 @@ int8_t bme280_soft_reset(const struct bme280_dev *dev)
|
|||||||
/* Write the soft reset command in the sensor */
|
/* Write the soft reset command in the sensor */
|
||||||
rslt = bme280_set_regs(®_addr, &soft_rst_cmd, 1, dev);
|
rslt = bme280_set_regs(®_addr, &soft_rst_cmd, 1, dev);
|
||||||
|
|
||||||
/* As per data sheet, startup time is 2 ms. */
|
if (rslt == BME280_OK)
|
||||||
|
{
|
||||||
|
/* If NVM not copied yet, Wait for NVM to copy */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
/* As per data sheet - Table 1, startup time is 2 ms. */
|
||||||
dev->delay_ms(2);
|
dev->delay_ms(2);
|
||||||
|
rslt = bme280_get_regs(BME280_STATUS_REG_ADDR, &status_reg, 1, dev);
|
||||||
|
} while ((rslt == BME280_OK) && (try_run--) && (status_reg & BME280_STATUS_IM_UPDATE));
|
||||||
|
|
||||||
|
if (status_reg & BME280_STATUS_IM_UPDATE)
|
||||||
|
{
|
||||||
|
rslt = BME280_E_NVM_COPY_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rslt;
|
return rslt;
|
||||||
|
4
bme280.h
4
bme280.h
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* @file bme280.h
|
* @file bme280.h
|
||||||
* @date 08 Mar 2019
|
* @date 26 Aug 2019
|
||||||
* @version 3.3.6
|
* @version 3.3.7
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* @file bme280_defs.h
|
* @file bme280_defs.h
|
||||||
* @date 08 Mar 2019
|
* @date 26 Aug 2019
|
||||||
* @version 3.3.6
|
* @version 3.3.7
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -148,6 +148,7 @@
|
|||||||
#define BME280_E_INVALID_LEN INT8_C(-3)
|
#define BME280_E_INVALID_LEN INT8_C(-3)
|
||||||
#define BME280_E_COMM_FAIL INT8_C(-4)
|
#define BME280_E_COMM_FAIL INT8_C(-4)
|
||||||
#define BME280_E_SLEEP_MODE_FAIL INT8_C(-5)
|
#define BME280_E_SLEEP_MODE_FAIL INT8_C(-5)
|
||||||
|
#define BME280_E_NVM_COPY_FAILED INT8_C(-6)
|
||||||
|
|
||||||
/**\name API warning codes */
|
/**\name API warning codes */
|
||||||
#define BME280_W_INVALID_OSR_MACRO INT8_C(1)
|
#define BME280_W_INVALID_OSR_MACRO INT8_C(1)
|
||||||
@ -237,6 +238,10 @@
|
|||||||
#define BME280_FILTER_COEFF_8 (0x03)
|
#define BME280_FILTER_COEFF_8 (0x03)
|
||||||
#define BME280_FILTER_COEFF_16 (0x04)
|
#define BME280_FILTER_COEFF_16 (0x04)
|
||||||
|
|
||||||
|
#define BME280_STATUS_REG_ADDR (0xF3)
|
||||||
|
#define BME280_SOFT_RESET_COMMAND (0xB6)
|
||||||
|
#define BME280_STATUS_IM_UPDATE (0x01)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Interface selection Enums
|
* @brief Interface selection Enums
|
||||||
*/
|
*/
|
||||||
|
@ -1,29 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
Linux userspace test code, simple and mose code directy from the doco.
|
* Linux userspace test code, simple and mose code directy from the doco.
|
||||||
compile like this: gcc linux_userspace.c ../bme280.c -I ../ -o bme280
|
* compile like this: gcc linux_userspace.c ../bme280.c -I ../ -o bme280
|
||||||
tested: Raspberry Pi.
|
* tested: Raspberry Pi.
|
||||||
Use like: ./bme280 /dev/i2c-0
|
* Use like: ./bme280 /dev/i2c-0
|
||||||
*/
|
*/
|
||||||
|
#include "bme280.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifdef __KERNEL__
|
||||||
#include <linux/i2c-dev.h>
|
#include <linux/i2c-dev.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "bme280.h"
|
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
|
||||||
|
void user_delay_ms(uint32_t period);
|
||||||
|
int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
|
||||||
|
void print_sensor_data(struct bme280_data *comp_data);
|
||||||
|
int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev);
|
||||||
|
|
||||||
int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
|
int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
|
||||||
{
|
{
|
||||||
if (write(fd, ®_addr, sizeof(reg_addr)) < sizeof(reg_addr))
|
write(fd, ®_addr, 1);
|
||||||
return BME280_E_COMM_FAIL;
|
read(fd, data, len);
|
||||||
if (read(fd, data, len) < len)
|
|
||||||
return BME280_E_COMM_FAIL;
|
return 0;
|
||||||
return BME280_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void user_delay_ms(uint32_t period)
|
void user_delay_ms(uint32_t period)
|
||||||
@ -34,6 +40,7 @@ void user_delay_ms(uint32_t period)
|
|||||||
int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
|
int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
|
||||||
{
|
{
|
||||||
int8_t *buf;
|
int8_t *buf;
|
||||||
|
|
||||||
buf = malloc(len + 1);
|
buf = malloc(len + 1);
|
||||||
buf[0] = reg_addr;
|
buf[0] = reg_addr;
|
||||||
memcpy(buf + 1, data, len);
|
memcpy(buf + 1, data, len);
|
||||||
@ -105,6 +112,7 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
|
|||||||
}
|
}
|
||||||
print_sensor_data(&comp_data);
|
print_sensor_data(&comp_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rslt;
|
return rslt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,11 +147,13 @@ int main(int argc, char* argv[])
|
|||||||
fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]);
|
fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#ifdef __KERNEL__
|
||||||
if (ioctl(fd, I2C_SLAVE, dev.dev_id) < 0)
|
if (ioctl(fd, I2C_SLAVE, dev.dev_id) < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n");
|
fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rslt = bme280_init(&dev);
|
rslt = bme280_init(&dev);
|
||||||
if (rslt != BME280_OK)
|
if (rslt != BME280_OK)
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* File bme280_selftest.c
|
* File bme280_selftest.c
|
||||||
* Date 08 Mar 2019
|
* Date 26 Aug 2019
|
||||||
* Version 3.3.6
|
* Version 3.3.7
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
* patent rights of the copyright holder.
|
* patent rights of the copyright holder.
|
||||||
*
|
*
|
||||||
* File bme280_selftest.h
|
* File bme280_selftest.h
|
||||||
* Date 08 Mar 2019
|
* Date 26 Aug 2019
|
||||||
* Version 3.3.6
|
* Version 3.3.7
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user