CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

BMP280 humidity doesn't work
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19145

View user's profile Send private message

PostPosted: Mon Sep 11, 2023 7:47 am     Reply with quote

No, I mean the bme280.c driver.
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

PostPosted: Mon Sep 11, 2023 7:52 am     Reply with quote

Ok I have to try it. I will inform here.

I have thinking before that I have BMP280 device.
Thanks much.
Ttelmah



Joined: 11 Mar 2010
Posts: 19145

View user's profile Send private message

PostPosted: Mon Sep 11, 2023 8:05 am     Reply with quote

Set up your chip like:
Code:

#define BME280_I2C_ADDRESS  0xEC
 
#include <18F2620.h>
#DEVICE ADC=10
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOPROTECT              //Code not protected from reading
#FUSES BROWNOUT               //Reset when brownout detected
#FUSES PUT                          //Power Up Timer
#FUSES NOCPD                     //No EE protection
#FUSES NODEBUG                 //No Debug mode for ICD
#FUSES NOLVP                      //No low voltage prgoming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES FCMEN                     //Fail-safe clock monitor enabled
#FUSES NOMCLR                   //Master Clear pin not enabled
#FUSES NOWRT                     
#use delay(internal = 8MHz)
#use rs232(baud=9600, parity=N,  UART1, errors, bits=8, BRGH1OK)  // RS232 settings
#use I2C(MASTER, I2C1, FAST = 400000. STREAM=STREAM_I2C_BME280)

#include <BME280.c>


This will make the driver use your I2C setup
Ttelmah



Joined: 11 Mar 2010
Posts: 19145

View user's profile Send private message

PostPosted: Mon Sep 11, 2023 8:21 am     Reply with quote

Let's also make some comments, and you will see why I am complaining
about the code:
Code:

  temp1=0;
  for( i=0;i<10;i++) {
     BMP280_readTemperature(&temperature);
     temp1  += temperature;
  } //OK at this point 'temp1' contains 10 readings summed
   temperature = temp1/10 ;
   //This /10 has now been put into temperature.
   //Don't use /10 for averaging. Use /2, /4 /8 or /16
   //Much more efficient for the maths.
   BMP280_readTemperature(&temperature);
   //You have now just thrown away all that work and got a single
   //reading again!... Duh.
   BMP280_readPressure(&pressure);// read pressure
   temperature -= 240; // calibrate  -2.c
   //OK have subtracted 2.4C
   printf("#TT15"); // # starts data string
 
    temperature -= 1.94; // caibrate
    //This though has subtracted 0.01C, and wasted a huge amount
    //of time to do it. The integer was converted to float, then 1.94
    //subtracted, then the result converted back to integer. Thousands
    //of instructions to just subtract 1.


The code is massively flawed in a lot of places.....
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

PostPosted: Mon Sep 11, 2023 12:30 pm     Reply with quote

Ttelmah,
thank you for commenting my code.
It will send the results only with 10 seconds, so it is not important to me.
==
I try the CCS own library BME280.c
The first time I got some results, but then when I tried again 2-20 timea I got only 0s.
I didn't edit the library.
Here are my results:
The First try
Probyte BME280 sender,LDR,NTC 11-Sep-23
#TT15+25.15,+55.27,084,464384.18,793608.94$
00.84$
#TT15+25.14,+52.87,084,464384.18,793608.94$
00.84$
#TT15+25.06,+50.47,084,464384.18,793608.94$
00.84$
====
The second anf more resulta.
Probyte BME280 sender,LDR,NTC 11-Sep-23

bme280=0
sensor mode=0
Vesion check =0
Temp right=0
Press right=0
Hum right=0
#TT15+25.46,+57.67,084,380498.10,793608.81$
========
And here are the my main code:

// define device I2C address: 0xEC or 0xEE (0xEE is library default address)
//#define BME280_I2C_ADDRESS 0xEC

#include <18F2620.h>
#DEVICE ADC=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOMCLR //Master Clear pin not enabled
#FUSES NOWRT
#use delay(internal = 8MHz)
#use rs232(baud=9600, parity=N, UART1, errors, bits=8, BRGH1OK) // RS232 settings
#use I2C(MASTER, I2C1, FAST = 400000)

#define LEDON output_high(PIN_C5); //punainen LED
#include "BMe280.c"
#include "ntc.c"


//signed int32 temperature;
signed int32 pTemp;
unsigned int32 pPress;
unsigned int32 pHum;
// measure ntc temp
void mittaa ( void)
{
unsigned int8 i=0 ;
restart_wdt(); // sample watcdog, if needed
temp=0;

for(i=0; i<multiplier; i++) //measure ntc 20 times and cound mean value
{
mittaa_ntc(); // measure NTC
steinhart1(); // count staninhArt
temp +=steinhart; // add to temp
}
temp = temp/multiplier ; // acalibrate if needed


}

unsigned int16 temp1 ;

void main()
{
int8 i, ok;
LEDON ;
delay_ms(100); // wait 0.1 second
printf("\rProbyte BME280 sender,LDR,NTC %s\r", __DATE__ );
ok = bme280_ok();
printf("\rbme280=%d", ok);

ok= bme280_set_mode(BM280_MODE_FORCED) ;
printf("\rsensor mode=%d", ok);
if( _bme280_version_check())
printf("\rVesion check =1");
else
printf("\rVesion check =0");


while(TRUE)
{
temp1=0;
for( i=0;i<10;i++) {
bme280_get_temperature(&pTemp);
temp1 += pTemp;
}
pTemp = temp1/10 ;

ok= bme280_get_temperature( & pTemp);
printf("\rTemp right=%d", ok);
ok= bme280_get_pressure(&pTemp,&pPress);
printf("\rPress right=%d", ok);
bme280_get_humidity(&pTemp, &pPress, &pHum);
printf("\rHum right=%d\r", ok);

// ptemp -= 240; //calibrate -2.c
mittaa(); // measure with NTC temp
measureLight(); // measure light
printf("#TT15"); // # starts the sentence
// temp =-temp; testing
if ( temp>0) // NTC temp
printf("+%05.2f,", temp);
else
printf("%05.2f,", temp);
temp -= 1.94; // calibrate

// ptemp= pTemp/100;
if(pTemp < 0)
{
pTemp = abs(pTemp); // abs: absolute value

printf("-%02Lu.%02Lu,", pTemp/ 100,pTemp% 100);
}
else {


printf("+%02Lu.%02Lu,", pTemp/100, pTemp % 100);

}
printf( "%03ld,", light ); //
// PPress =pPress/ 100;
printf( "%04Lu.%02Lu,", pPress/100, pPress % 100);
// pHum =pHum/100;
printf( "%02Lu.%02Lu$\r", pHum / 1024, ((pHum* 100)/1024) % 100);


delay_ms(10000); // wait 2 seconds
}

}
// end of code.¯

Why I got the first time some results?
And then nothing
Is my working sensor somehow wrong to CCS library?

Pekka
Ttelmah



Joined: 11 Mar 2010
Posts: 19145

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 2:26 am     Reply with quote

As you post, the library will be ignoring your I2C setup, and clocking the
I2C at 1MHz. Unless your bus is very short this is unlikely to work.
You need to setup the I2C as I show.
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 4:14 am     Reply with quote

Than you Ttelmah

I moved I2C switching speed to 10000.
But it doesn't help.
#use I2C(MASTER, I2C1, FAST = 10000)

I connected the SDO input to ground, but it doesn't help.
There were the BME280 initialize problem.
I can't find PConfig parameters from the library.
The function void bme280_prepare_defaults(bme280_init_t *pConfig) I can't use it because I do not know what is pConfig
==
Here is my results
Pekka Ritamaki

Probyte BME280 sender,LDR,NTC 12-Sep-23

bme280=0
sensor mode=0
Vesion check =0
pTemp 0, pPress=572785220, pHum =0
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
Temp right=0 pTemp 0
bme280_get_humidity()
NOT_INIT
Press right=0 pPress 572785220 pTemp 0
bme280_get_humidity()
NOT_INIT
Hum right=0 &pHum 0 pTemp 0 pPress 572785220
#TT15+25.36,+00.00,065,5727852.20,00.00$

pTemp 0, pPress=572785220, pHum =0
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
bme280_get_humidity()
NOT_INIT
Temp right=0 pTemp 0
bme280_get_humidity()
NOT_INIT
Press right=0 pPress 572785220 pTemp 0
bme280_get_humidity()
NOT_INIT
Hum right=0 &pHum 0 pTemp 0 pPress 572785220
#TT15+25.40,+00.00,084,5727852.20,00.00$
Ttelmah



Joined: 11 Mar 2010
Posts: 19145

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 7:03 am     Reply with quote

You are missing the point.
The driver will not use your I2C setup.
You need either to use a named stream as I show, or get rid of your
#use I2C line and have:
Code:

#define BME_I2C_BAUD 100000

#include <BME280.c>


The driver sets up the I2C for you unless there is a named stream
already setup.
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 9:31 am     Reply with quote

Ttelmah
I corrected my I2C
And use only what has done in library for example

#include <18F2620.h>
#DEVICE ADC=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOMCLR //Master Clear pin not enabled
#FUSES NOWRT
#use delay(internal = 8MHz)
#use rs232(baud=9600, parity=N, UART1, errors, bits=8, BRGH1OK) // RS232 settings
//#use I2C(MASTER, I2C1, FAST = 10000)

#define LEDON output_high(PIN_C5); //red LED
#include "BMe280.c"



signed int32 pTemp;
unsigned int32 pPress;
unsigned int32 pHum;
// measure ntc temp
void main()
{
int8 i ;
int1 ok;
bme280_init();
bme280_set_mode(BM280_MODE_NORMAL);
for(;;) {
ok= bme280_ok() ;
printf("\rVesion check %d", _bme280_version_check());

delay_ms(1000);
ok = bme280_get_humidity(&pTemp, &pPress, &pHum);
if (!ok)
printf("\r Error reading BME280 sensor!\r\n");
else
printf("\rTemp=%ld Press=%lu Hum=%lu\r\n", ptemp, pPress, pHum);
}

}
==
Here is the result
Vesion check 0
bme280_init
BM280_OS280_1x = 1
BM280_TIMING_12 = 2
bme280_prepare_defaults
bme280_init()
RET=0
Vesion check 0
bme280_get_humidity()
NOT_INIT
Error reading BME280 sensor!
==
I have closed SDO pin to ground.
Hmm, what is wrong?
==
Regards Pekka Ritamaki
gaugeguy



Joined: 05 Apr 2011
Posts: 281

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 9:38 am     Reply with quote

And you still have not added the line Ttelmah asked you to.
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 10:39 am     Reply with quote

gaugeguy, I removed my I2C command, now it comes from library with speed 1000000
//#use I2C(MASTER, I2C1, FAST = 10000)

Here is the library code
#ifndef BME280_I2C_ADDRESS
#define BME280_I2C_ADDRESS 0xEC
#endif

#ifndef BME280_I2C_BAUD
//spec says max i2c clock is 3.4MHz, but I wasn't getting anywhere near that fast.
#define BME280_I2C_BAUD 1000000
#endif

Hopefully some can help
Pekka
Ttelmah



Joined: 11 Mar 2010
Posts: 19145

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 11:14 am     Reply with quote

Your board, unless it has very short connections directly to the chip (it
doesn't, since you dhow a link to a module), will not run at 1MHz.
Hence you need to slow the clock down with the line I showed.
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 11:43 am     Reply with quote

I tried to remove the shot from SDO to gnd, but it doesn't help
Pekka
dyeatman



Joined: 06 Sep 2003
Posts: 1908
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Sep 12, 2023 11:50 am     Reply with quote

You do realize that every time you change the SDO connection your are changing the device address..
with SDO tied to ground you need to be using address 0xEC,
with it cut (tied to 3.3) you need to use address 0xEE

Also, you still haven't fixed the speed like he told you to.
_________________
Google and Forum Search are some of your best tools!!!!
pekka1234



Joined: 28 May 2017
Posts: 74

View user's profile Send private message

BME280 error
PostPosted: Tue Sep 12, 2023 12:00 pm     Reply with quote

OK , put it back, but it doesn't help
bme280_init
BM280_OS280_1x = 1
BM280_TIMING_12 = 2
bme280_prepare_defaults
bme280_init()
RET=0
Vesion check 0
bme280_get_humidity()
NOT_INIT

Pekka
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group