cancel
Showing results for 
Search instead for 
Did you mean: 

Blocking behavior when intergrating BME688 to Nucleo board

HNguy.25
Associate III

Currently, I am working with an IoT application on the board Nucleo-WL55JC1 with the sensor BME688. The example I am using is LoRaWAN_End_Node downloaded from STM32Cube MX. 

What I did: I initialized the the BME688 and set up some configuration after the initialization of MX_LoRaWAN_Init(). I, then, set up some configuration outside the while loop. I "extern"ed the variables below so that I can used them elsewhere:

struct bme68x_dev bme;
 
struct bme68x_conf conf;
 
struct bme68x_heatr_conf heatr_conf;

Order of initialization are below:

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LoRaWAN_Init();
MX_I2C3_Init();
/* USER CODE BEGIN 2 */
int8_t rslt = bme68x_interface_init(&bme, BME68X_I2C_INTF);
rslt = bme68x_init(&bme);
 
//Set up the measurement
conf.filter = BME68X_FILTER_OFF;
conf.odr = BME68X_ODR_NONE;
conf.os_hum = BME68X_OS_16X;
conf.os_pres = BME68X_OS_1X;
conf.os_temp = BME68X_OS_2X;
rslt = bme68x_set_conf(&conf, &bme);
heatr_conf.enable = BME68X_ENABLE;
heatr_conf.heatr_temp = 300;
heatr_conf.heatr_dur = 100;
rslt = bme68x_set_heatr_conf(BME68X_SEQUENTIAL_MODE, &heatr_conf, &bme);
 
rslt = bme68x_set_op_mode(BME68X_SEQUENTIAL_MODE, &bme);

For obtaining the temperature/pressure/humidity/gas level, I got the data of the sensor in the function SendTxData in the file lora_app.c:

struct bme68x_data data;
  uint32_t del_period;
  uint8_t n_fields;
 
#ifdef CAYENNE_LPP
  uint8_t channel = 0;
#else
  uint16_t pressure = 0;
  int16_t temperature = 0;
  uint16_t humidity = 0;
  uint32_t i = 0;
  int32_t latitude = 0;
  int32_t longitude = 0;
  uint16_t altitudeGps = 0;
#endif /* CAYENNE_LPP */
 
  //EnvSensors_Read(&sensor_data);
  del_period = bme68x_get_meas_dur(BME68X_SEQUENTIAL_MODE, &conf, &bme) + (heatr_conf.heatr_dur * 1000);
  bme.delay_us(del_period, bme.intf_ptr);
  int8_t rslt = bme68x_get_data(BME68X_SEQUENTIAL_MODE, &data, &n_fields, &bme);
  float senTemp = data.temperature;
  float senPres = data.pressure;
  float senHumid = data.humidity;

The problem: as in the code, I set the sensor to work in sequential mode, however, the whole setup stopped working after the first measurement. The same thing happened when I set the sensor to work in parallel mode. Sleep mode worked okay and for Forced mode, I could achieve the first measurement before the sensor turned to sleep mode (correct).

0693W00000Suk0QQAR.pngQuestion: Where should I start tracking the problem or how do I fix this problem?

I hope to have responses from you.

Thank you very much, Huy Nguyen.

4 REPLIES 4

Don't use delays. Code something in a stateful fashion so you can come back later and pick-up where you left off.

Walk all of the code supporting the sensor, and the datasheets to understand the expectations and process.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HNguy.25
Associate III

Hello @Tesla, thank you for your response.

  • For the first point: can you be more specific about this approach?. As I understand I should put some checking variable with which I am able to know where the error/stopping occurs?
  • For the second point: Before I intergrated the code of BME688 into the LoRaWAN_End_Node, I already have a different project in which I simply read the data from the BME688 and output the values. ​In this project, I tried all modes and it worked okay.

I think since the LoRaWAN_End_Node has its handler, timer, scheduler, etc., the intergration of BME688 might interfere the whole process. But I am not sure how to start fixing this issue.

I mean stop expecting sequential/linear code execution (end-to-end), that instead you get small bites of time, and in each you do the next thing that's needs doing and LEAVE. You don't sit spinning in delay loops, or blocking. Try to move to an asynchronous model where you get alerted when something is done/ready.

If the sensor has a periodicity, read that once, and use timers to pace the requesting of that data at required intervals, not delays.

That you have data ready when using SendTxData()

That you understand what the BME688 library code is doing, or needs to do, under the surface, not at the top level. This will be especially true if the paradigm if wrong, and doesn't fit how the LoRa device needs to perform/respond. Watch also that things don't get powered down when you need them, and that if they get powered down you recover.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you for your clarification. Right now instead of adding the sensor reading in the middle of SendTxData(). I declared a sensor reading as a function and register it as a task. That task has the same priority as the SendTxData():

UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), UTIL_SEQ_RFU, RetrieveBMEData);

I also did as you suggested: I declared 4 private variables in the lora_app.c namely sensorTemp, sensorHumd, sensorPress, and sensorGas. These variables are updated when the sensor reading function run.

However, the program still stopped working.

Should I continue with this solution (making the sensor reading as a task) but change the priority of the newly declared function? In that case, what should be the priority of this function?