/**************************************************************************** * * \section Disclaimer * * Common: * Bosch Sensortec products are developed for the consumer goods industry. * They may only be used within the parameters of the respective valid * product data sheet. Bosch Sensortec products are provided with the * express understanding that there is no warranty of fitness for a * particular purpose.They are not fit for use in life-sustaining, * safety or security sensitive systems or any system or device * that may lead to bodily harm or property damage if the system * or device malfunctions. In addition,Bosch Sensortec products are * not fit for use in products which interact with motor vehicle systems. * The resale and or use of products are at the purchasers own risk and * his own responsibility. The examination of fitness for the intended use * is the sole responsibility of the Purchaser. * * The purchaser shall indemnify Bosch Sensortec from all third party * claims, including any claims for incidental, or consequential damages, * arising from any product use not covered by the parameters of * the respective valid product data sheet or not approved by * Bosch Sensortec and reimburse Bosch Sensortec for all costs in * connection with such claims. * * The purchaser must monitor the market for the purchased products, * particularly with regard to product safety and inform Bosch Sensortec * without delay of all security relevant incidents. * * Engineering Samples are marked with an asterisk (*) or (e). * Samples may vary from the valid technical specifications of the product * series. They are therefore not intended or fit for resale to third * parties or for use in end products. Their sole purpose is internal * client testing. The testing of an engineering sample may in no way * replace the testing of a product series. Bosch Sensortec assumes * no liability for the use of engineering samples. * By accepting the engineering samples, the Purchaser agrees to indemnify * Bosch Sensortec from all claims arising from the use of engineering * samples. * * Special: * This software module (hereinafter called "Software") and any information * on application-sheets (hereinafter called "Information") is provided * free of charge for the sole purpose to support your application work. * The Software and Information is subject to the following * terms and conditions: * * The Software is specifically designed for the exclusive use for * Bosch Sensortec products by personnel who have special experience * and training. Do not use this Software if you do not have the * proper experience or training. * * This Software package is provided `` as is `` and without any expressed * or implied warranties,including without limitation, the implied warranties * of merchantability and fitness for a particular purpose. * * Bosch Sensortec and their representatives and agents deny any liability * for the functional impairment * of this Software in terms of fitness, performance and safety. * Bosch Sensortec and their representatives and agents shall not be liable * for any direct or indirect damages or injury, except as * otherwise stipulated in mandatory applicable law. * * The Information provided is believed to be accurate and reliable. * Bosch Sensortec assumes no responsibility for the consequences of use * of such Information nor for any infringement of patents or * other rights of third parties which may result from its use. * No license is granted by implication or otherwise under any patent or * patent rights of Bosch. Specifications mentioned in the Information are * subject to change without notice. **************************************************************************/ #include "bmp280_task.h" #ifdef BMP280_SENSOR #include ".\bmp280_v3.3.4\bmp280.h" //#include ".\bmp280_v3.2.0\bmp280_develop\bmp280.h" #define I2C_ADDRESS BMP280_I2C_ADDR_PRIM struct bmp280_dev dev; extern volatile uint8_t int0_flag; extern volatile uint8_t int1_flag; #ifdef SUPPORT_I2C int8_t BST_sensor_i2c_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len) { return SensorAPI_I2Cx_Read(dev_addr, reg_addr, data, len); } int8_t BST_sensor_i2c_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len) { return SensorAPI_I2Cx_Write(dev_addr, reg_addr, data, len); } void bmp280_I2C_config(struct bmp280_dev *dev) { /* Modify the parameters */ dev->dev_id = I2C_ADDRESS << 1; dev->intf = BMP280_I2C_INTF; dev->read = (bmp280_com_fptr_t)BST_sensor_i2c_read; dev->write = (bmp280_com_fptr_t)BST_sensor_i2c_write; dev->delay_ms = (bmp280_delay_fptr_t)HAL_Delay; PDEBUG("bmp280_I2C_config\n"); return; } #endif #ifdef SUPPORT_SPI int8_t BST_sensor_spi_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len) { // reg_addr |=0x80; return SensorAPI_SPIx_Read(dev_addr, reg_addr, data, len); } int8_t BST_sensor_spi_write(uint8_t dev_addr,uint8_t reg_addr, uint8_t *data, uint16_t len) { // reg_addr &=0x7f; // HAL_Delay(1); return SensorAPI_SPIx_Write(dev_addr, reg_addr, data, len); } void bmp280_SPI_config(struct bmp280_dev *dev) { /* Modify the parameters */ // dev->dev_id = I2C_ADDRESS << 1; dev->intf = BMP280_SPI_INTF; dev->read = (bmp280_com_fptr_t)BST_sensor_spi_read; dev->write = (bmp280_com_fptr_t)BST_sensor_spi_write; dev->delay_ms = (bmp280_delay_fptr_t)HAL_Delay; return; } #endif void print_rslt(const char api_name[], int8_t rslt) { if (rslt != BMP280_OK) { PDEBUG("%s\t", api_name); if (rslt == BMP280_E_NULL_PTR) { PDEBUG("Error [%d] : Null pointer error\r\n", rslt); } else if (rslt == BMP280_E_COMM_FAIL) { PDEBUG("Error [%d] : Bus communication failed\r\n", rslt); } else if (rslt == BMP280_E_IMPLAUS_TEMP) { PDEBUG("Error [%d] : Invalid Temperature\r\n", rslt); } else if (rslt == BMP280_E_DEV_NOT_FOUND) { PDEBUG("Error [%d] : Device not found\r\n", rslt); } else { /* For more error codes refer "*_defs.h" */ PDEBUG("Error [%d] : Unknown error code\r\n", rslt); } } } void BMP280_MODULE_INIT(void) { int8_t rslt = BMP280_OK; /* Sensor_0 interface over SPI with native chip select line */ #ifdef SUPPORT_I2C bmp280_I2C_config(&dev); #endif #ifdef SUPPORT_SPI BMA_SPI_MODE_CONFIG(); bmp280_SPI_config(&dev); #endif HAL_Delay(1); BMI4XX_REG_READ(BMP280_I2C_ADDR_PRIM,0x00,1);//i2c rslt = bmp280_init(&dev); PDEBUG("rslt =0x%x \r\n",rslt); PDEBUG("dev.chip_id =0x%x,dev.dev_id =0x%x \r\n",dev.chip_id,dev.dev_id); } int8_t set_sensor_normal_mode(struct bmp280_dev *dev) { int8_t rslt; /* Used to select the settings user needs to change */ struct bmp280_config conf; rslt = bmp280_get_config(&conf, dev); print_rslt(" bmp280_get_config status", rslt); /* configuring the temperature oversampling, filter coefficient and output data rate */ /* Overwrite the desired settings */ conf.filter = BMP280_FILTER_COEFF_16;//BMP280_FILTER_COEFF_2; /* Pressure oversampling set at 4x */ conf.os_pres = BMP280_OS_16X;//BMP280_OS_4X; /* Pressure oversampling set at 4x */ conf.os_temp = BMP280_OS_2X;//BMP280_OS_4X; /* Setting the output data rate as 1HZ(1000ms) */ conf.odr = BMP280_ODR_500_MS;//BMP280_ODR_1000_MS; rslt = bmp280_set_config(&conf, dev); print_rslt(" bmp280_set_config status", rslt); rslt = bmp280_set_power_mode(BMP280_NORMAL_MODE, dev); PDEBUG("set_normal_mode rslt =0x%x \r\n",rslt); return rslt; } //Reading sensor data //Example for reading all sensor data int8_t get_sensor_data(struct bmp280_dev *dev) { int8_t rslt; struct bmp280_uncomp_data ucomp_data; uint32_t pres32, pres64; double pres; int32_t temp32; double temp; /* Reading the raw data from sensor */ rslt = bmp280_get_uncomp_data(&ucomp_data, dev); #if 0 /* Getting the compensated pressure using 32 bit precision */ rslt = bmp280_get_comp_pres_32bit(&pres32, ucomp_data.uncomp_press, dev); /* Getting the compensated pressure using 64 bit precision */ rslt = bmp280_get_comp_pres_64bit(&pres64, ucomp_data.uncomp_press, dev); /* Getting the compensated pressure as floating point value */ rslt = bmp280_get_comp_pres_double(&pres, ucomp_data.uncomp_press, dev); PDEBUG("Pressure UP: %ld, P32: %ld, P64: %ld, P64N: %ld, P: %f\r\n", ucomp_data.uncomp_press,pres32,pres64,(pres64 / 256),pres); #endif PDEBUG("Sensor ucomp_data.uncomp_temp: %ld\r\n",ucomp_data.uncomp_temp); /* Getting the 32 bit compensated temperature */ rslt = bmp280_get_comp_temp_32bit(&temp32, ucomp_data.uncomp_temp, dev); /* Getting the compensated temperature as floating point value */ rslt = bmp280_get_comp_temp_double(&temp, ucomp_data.uncomp_temp, dev); PDEBUG("Temperature UT: %ld, T32: %ld, T: %f \r\n", ucomp_data.uncomp_temp, temp32, temp); HAL_Delay(50); /* Sleep time between measurements = BMP280_ODR_1000_MS */ return rslt; } void StartBstTask(void const * argument) { PDEBUG("\n"); PDEBUG("***************Enter BMP280 StartBstTask()!************************\r\n"); PDEBUG("\n"); BMP280_MODULE_INIT(); set_sensor_normal_mode(&dev); PDEBUG("Enter BMP280 Task Loop!\r\n"); for(;;) { get_sensor_data(&dev); // vTaskDelay(1000); osDelay(1); } } #endif