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?
... View more