01-07-2021 11:16 AM
Hello,
I am trying to get the BME680 working with the Bosch Lib and a PIC32MM0256GPM064.
I am able to read and write registers and see the correct values via printf's and on my logic analyzer.
If the example code is reading the sensor data via bme680_get_sensor_data the rslt is everytime BME680_W_NO_NEW_DATA.
I also tried it with a PIC18F46K42 and got the same problem (but different I2C code provided by MCC).
My code to verify the I2C functions:
user_i2c_read(0x77, 0xD0, buffer, 1);
printf("Read Reg 0x%X: 0x%X (0x61 expected)\n",(0xD0),buffer[0]);
user_delay_ms(100);
buffer[0] = 0x03;
user_i2c_write(0x77, 0x72, buffer, 1);
printf("writing 0x03 to 0x72...\n");
buffer[0] = 0x04;
user_i2c_write(0x77, 0x64, buffer, 1);
printf("writing 0x04 to 0x64...\n");
buffer[0] = 0x05;
user_i2c_write(0x77, 0x5A, buffer, 1);
printf("writing 0x05 to 0x5A...\n");
buffer[0] = 0x06;
user_i2c_write(0x77, 0x50, buffer, 1);
printf("writing 0x06 to 0x50...\n");
user_delay_ms(100);
buffer[0] = 0;
user_i2c_read(0x77, 0x72, buffer, 1); // read
printf("Read Reg 0x%X: 0x%X (0x03 expected)\n",(0x72),buffer[0]);
buffer[0] = 0;
user_i2c_read(0x77, 0x64, buffer, 1); // read
printf("Read Reg 0x%X: 0x%X (0x04 expected)\n",(0x64),buffer[0]);
buffer[0] = 0;
user_i2c_read(0x77, 0x5A, buffer, 1); // read
printf("Read Reg 0x%X: 0x%X (0x05 expected)\n",(0x5A),buffer[0]);
buffer[0] = 0;
user_i2c_read(0x77, 0x50, buffer, 1); // read
printf("Read Reg 0x%X: 0x%X (0x06 expected)\n",(0x50),buffer[0]);
Console output is:
Logic Analyzer:
Looks good for me.
But if I let the example code running, BME680_W_NO_NEW_DATA is the result.
If I let it run once and then read out the wait and heat registers there are wrong (but constant) numbers in.
What could I do? Is my verification correct?
Thanks!
01-12-2021 02:48 AM
Hi Sir:
Based on the source code you posted, I thought it was from BME680 api code, not BESC library referecn code.
Do you confirm whether I2C reading and writing was successful?
Do you read out BME680 CHIP ID? First you should check your I2C communication and then continue to verify it with BME680 code.
If unsuccessful, maybe you should check it on your platform, we have no way to comfirm your I2C communication.
01-12-2021 09:41 AM
Hi,
please read what I am writing.
I wrote two times how I am testing the I2C reading and writing. Its successful.
And in my first post I read out the chip id. Have a look please.
The BESC library will you the BME680 api code. So I can also go with the BME680 api first and then put the "layer" of the BESC on top if I am needed.
01-12-2021 12:42 PM - edited 01-12-2021 12:44 PM
I did another test, I wrote some data to the config registers and read back the data but without the library to test the i2c functions.
My code:
while(1){
// reset
buffer[0] = 0xB6;
user_i2c_write(0x77, 0xE0, buffer, 1);
user_delay_ms(1000);
// osrs h
buffer[0] = 0b00000001;
user_i2c_write(0x77, 0x72, buffer, 1);
user_delay_ms(100);
// osrs t p
buffer[0] = 0b00100100;
user_i2c_write(0x77, 0x74, buffer, 1);
user_delay_ms(100);
// filter
buffer[0] = 0b00000100;
user_i2c_write(0x77, 0x75, buffer, 1);
user_delay_ms(100);
// run gas
buffer[0] = 0b00010000;
user_i2c_write(0x77, 0x71, buffer, 1);
user_delay_ms(100);
// nb_conv
buffer[0] = 0b00000001;
user_i2c_write(0x77, 0x71, buffer, 1);
user_delay_ms(100);
// gas_wait
buffer[0] = 100;
user_i2c_write(0x77, 0x64, buffer, 1);
user_delay_ms(100);
// res_heat
buffer[0] = 100;
user_i2c_write(0x77, 0x5A, buffer, 1);
user_delay_ms(100);
while(1){
// forced
buffer[0] = 0x01 | 0b00100100;
user_i2c_write(0x77, 0x74, buffer, 1);
user_delay_ms(100);
// data ready
buffer[0] = 0;
user_i2c_read(0x77, 0x1D, buffer, 1); // read
//printf("Read Reg 0x%X: 0x%X (0x80 expected)\n",(0x1D),buffer[0]);
user_delay_ms(100);
if(buffer[0] & 0x80){
user_i2c_read(0x77, 0x22, buffer, 3); // read
uint32_t adc_temp = 0;
adc_temp = (uint32_t) (((uint32_t) buffer[0] * 4096) | ((uint32_t) buffer[1] * 16) | ((uint32_t) buffer[2] / 16));
printf("Temp: %i \t",adc_temp);
//printf("Temp B0: %i, B1: %i, B2: %i\n",buffer[0], buffer[1], buffer[2]);
user_delay_ms(100);
user_i2c_read(0x77, 0x25, buffer, 2); // read
uint32_t adc_hum = 0;
adc_hum = (uint16_t) (((uint32_t) buffer[0] * 256) | (uint32_t) buffer[1]);
printf("Hum: %i \t",adc_hum);
//printf("Hum B0: %i, B1: %i\n",buffer[0], buffer[1]);
user_delay_ms(100);
user_i2c_read(0x77, 0x1F, buffer, 3); // read
uint32_t adc_pres = 0;
adc_pres = (uint32_t) (((uint32_t) buffer[0] * 4096) | ((uint32_t) buffer[1] * 16) | ((uint32_t) buffer[2] / 16));
printf("Press: %i \t",adc_pres);
user_delay_ms(100);
user_i2c_read(0x77, 0x2A, buffer, 2); // read
uint32_t adc_gas_res = 0;
adc_gas_res = (uint16_t) ((uint32_t) buffer[0] * 4 | (((uint32_t) buffer[1]) / 64));
printf("Gas: %i \n",adc_gas_res);
user_delay_ms(500);
}
}
}
And I am getting:
Temp: 30063 <9>Hum: 20284 <9>Press: 16674 <9>Gas: 0 <\n>
Temp: 30064 <9>Hum: 20282 <9>Press: 16681 <9>Gas: 0 <\n>
Temp: 30064 <9>Hum: 20281 <9>Press: 16693 <9>Gas: 0 <\n>
Temp: 30080 <9>Hum: 20284 <9>Press: 16699 <9>Gas: 0 <\n>
Temp: 30088 <9>Hum: 20284 <9>Press: 16710 <9>Gas: 0 <\n>
Temp: 30100 <9>Hum: 20285 <9>Press: 16707 <9>Gas: 0 <\n>
Looks like the sensor is working. Temperature is about 30 degrees, humidity at 20%, if I breath the sensor the temperature and humidity is rising.
But I still don't know why the library is not working... I don't have an idea what I can do... The libary will not see the new_data bit but why?
01-13-2021 03:55 AM
Hi Sir:
Please see the attachment, which is my example code of BME680 API based on STM32 platform, like your code you posted.
See the following log, temperature and gas resistance also can be outputed.
T: 25.96 degC, P: 1018.63 hPa, H 20.94 %rH , G: 838041 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.94 %rH , G: 830224 ohms
T: 25.96 degC, P: 1018.63 hPa, H 20.94 %rH , G: 838568 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.93 %rH , G: 826625 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.93 %rH , G: 830224 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.93 %rH , G: 838041 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.92 %rH , G: 835419 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.94 %rH , G: 833333 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.94 %rH , G: 834897 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.93 %rH , G: 837516 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.93 %rH , G: 839623 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.94 %rH , G: 841210 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.93 %rH , G: 833333 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.94 %rH , G: 840151 ohms
T: 25.96 degC, P: 1018.65 hPa, H 20.92 %rH , G: 847619 ohms
T: 25.96 degC, P: 1018.63 hPa, H 20.93 %rH , G: 840151 ohms
01-13-2021 10:26 AM - edited 01-13-2021 10:36 AM
Good Morning,
looks like my code. I can't find big differences. Please have a look into my c code. But its the example code from the bosch git site...
I switched to SPI. Now the rslt is not no data anymore. The library runs but the values are constant all the time.
T: 33.38 degC, P: 708.66 hPa, H 100.00 %rH <\r><\n>
T: 33.38 degC, P: 708.66 hPa, H 100.00 %rH <\r><\n>
T: 33.38 degC, P: 708.66 hPa, H 100.00 %rH <\r><\n>
I am using a PIC18F46K42, XC8 compiler v2.31, MCC 5.0.2 and also tried an PIC32.
Here my logic analyzer plot from the reading of the data. (splitted in two graphics because there is a small delay between)
Could you share some of yours please?
Do you see a problem in my c code?