When I use the below-mentioned function in the void loop it works fine, but when I use this function in some external defined if in a function it gets stuck at Wire.endTransmission();. The other if function is also stated below.
I am using Redbear Blendv2 for the testing of this code and also have attached the ino file for any clarification.
void readData()
{
Serial.println(“Inside read”);
int i = 0;
uint32_t data[8];
Wire.beginTransmission(BME280_ADDRESS);
Serial.println(“After begin”);
Wire.write(0xF7);
Serial.println(“After write”);
Wire.endTransmission();
Serial.println(“After end”);
Wire.requestFrom(BME280_ADDRESS,8);
Serial.println(“After request”);
while(Wire.available()){
data = Wire.read();
- i++;*
- Serial.println(“Inside while of read”);*
- }*
- pres_raw = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);*
- temp_raw = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4);*
- hum_raw = (data[6] << 8) | data[7];*
}
void m_status_check_handle() {
if (analog_enabled && k==5) { - Serial.print(“Inside Environment”);*
- // if analog reading enabled*
- // Read and send out*
- // uint16_t value = analogRead(ANALOG_IN_PIN_X);*
- //uint16_t value1 = analogRead(ANALOG_IN_PIN_Y);*
- //uint16_t value2 = analogRead(ANALOG_IN_PIN_Z);*
- double temp_act = 0.0, press_act = 0.0,hum_act=0.0;*
- signed long int temp_cal;*
- unsigned long int press_cal,hum_cal;*
- readData();*
- temp_cal = calibration_T(temp_raw);*
- press_cal = calibration_P(pres_raw);*
- hum_cal = calibration_H(hum_raw);*
- temp_act = (double)temp_cal / 100.0;*
- press_act = (double)press_cal / 100.0;*
- hum_act = (double)hum_cal / 1024.0;*
- uint16_t hum_act_new= (uint16_t)hum_act;*
- uint16_t press_act_new= (uint16_t)press_act;*
- uint16_t temp_act_new= (uint16_t)temp_act;*
- Serial.print("TEMP : ");*
- Serial.print(temp_act_new);*
- Serial.print(" DegC PRESS : ");*
- Serial.print(press_act_new);*
- Serial.print(" hPa HUM : ");*
- Serial.print(hum_act_new);*
- Serial.println(" %"); *
- buf[0] = (0x0B);*
- buf[1] = (hum_act_new >> 8);*
- buf[2] = (hum_act_new);*
- buf[3] = (0x0A);*
- buf[4] = (0x0B);*
- buf[5] = (press_act_new >> 8);*
- buf[6] = (press_act_new);*
- buf[7] = (0x0A);*
- buf[8] = (0x0B);*
- buf[9] = (temp_act_new >> 8);*
- buf[10] = (temp_act_new);*
- ble.updateCharacteristicValue(characteristic2.getValueAttribute().getHandle(), buf, 9);*
- }*
}
BME280.ino (20 KB)