|
|
View previous topic :: View next topic |
Author |
Message |
akay
Joined: 29 Sep 2020 Posts: 17
|
bme 280 problem? HOW CAN I READ TEMP OR PRESSURE VALUE? |
Posted: Mon Nov 02, 2020 4:33 pm |
|
|
I wrote a simple code to read temperature with bme280 sensor .. but it couldnt work? please somebody help me about that.. Code: | #define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define LCD_ENABLE_PIN PIN_B3
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NODEBUG
#define use_portb_lcd TRUE
#use delay(clock = 8000000)
//24volt/<LCD.C>k istenilen en yüksek voltaj deðeri/ gerilim bölücüden çýkan voltaj
#include <lcd.c>
#include <BMe280.c>
#use i2c(master, sda=PIN_c4, scl=PIN_c3)
signed int32 pTemp;
void main()
{
lcd_init();
bme280_init();
DELAY_MS(25);
while(TRUE)
{
bme280_get_temperature(pTemp);
delay_ms(100);
lcd_gotoxy(1,2);
printf(lcd_putc," %d" pTemp);
delay_ms(20);
}
} |
LIBRARY CODE
Code: | ///////////////////////////////////////////////////////////////////////////
//// ////
//// bme280.c ////
//// ////
//// Driver for Bosch BME280 Environmental sensor. This sensor can ////
//// read temperature, pressure and humidity. This driver returns ////
//// calibrated/compensated values by using the trim values on the ////
//// sensor. At this time this driver only supports I2C mode, it ////
//// doesn't support SPI mode. ////
//// ////
//// ////
//// API ////
//// ----------------------------------------------------------------- ////
//// ////
//// ok = bme280_get_temperature(signed int32 *pTemp) ////
//// ok = bme280_get_pressure(signed int32 *pTemp, ////
//// unsigned int32 *pPress) ////
//// ok = bme280_get_humidity(signed int32 *pTemp, ////
//// unsigned int32 *pPress, unsigned int32 *pHum) ////
|
+++++++++++++++++++++
Library code removed.
Reason: CCS forum rule #10:
10. Don't post the CCS example code or drivers, or ask for such code and drivers.
Forum rules: http://www.ccsinfo.com/forum/viewtopic.php?t=26245
- Forum Moderator
+++++++++++++++++++++ |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 02, 2020 5:01 pm |
|
|
Notice that the definition of the function shows that you must pass it
a pointer to a signed int32.
Quote: | bme280_get_temperature(signed int32 *pTemp) |
That means you pass it the address of the int32.
Do it like this:
Quote: | bme280_get_temperature(&pTemp); |
|
|
|
akay
Joined: 29 Sep 2020 Posts: 17
|
|
Posted: Mon Nov 02, 2020 5:14 pm |
|
|
PCM programmer wrote: | Notice that the definition of the function shows that you must pass it
a pointer to a signed int32.
Quote: | bme280_get_temperature(signed int32 *pTemp) |
That means you pass it the address of the int32.
Do it like this:
Quote: | bme280_get_temperature(&pTemp); |
|
i dont understand what did you mean? by the way when i write this code "printf(lcd_putc," %d" pTemp);" i received this warning "Print format type invalid" but i use signed int? why am i getting this warning? could you please edit this code? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 02, 2020 5:38 pm |
|
|
You need to read about using pointers in the C language.
Use Google to search for articles on this.
Read the CCS manual for printf. If you want to print signed numbers
larger than int8, you need to use "%ld". Put the letter 'L' in front of the 'd'. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Mon Nov 02, 2020 6:16 pm |
|
|
You could easily have a basic hardware problem...
That PIC is designed to run on 5 volts, the BME280 sensor only 3 volts (most peripherals are 3 volts these days). You do need 'logic level conversion' to allow the PIC to control/receieve data from the device. If you bought a 'module' PCB that has the 'sensor', it might have the LLC parts on it. The datasheet should say ....
As it is an I2C device, download PCMPs I2C scanner program, located in the 'code library' here.
Run it to confirm the PIC can 'see' the BME280 device. If found, it's device address will be sent to the PC.
You should always run the 'scanner' program for every I2C device.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Tue Nov 03, 2020 1:11 am |
|
|
This "Print format type invalid" is because pTemp, is an int32.
Your printf, uses %d. %d is for a standard length integer. To print a
'long' integer, it needs %ld. Note the 'l'..... |
|
|
akay
Joined: 29 Sep 2020 Posts: 17
|
|
Posted: Tue Nov 03, 2020 8:54 am |
|
|
temtronic wrote: | You could easily have a basic hardware problem...
That PIC is designed to run on 5 volts, the BME280 sensor only 3 volts (most peripherals are 3 volts these days). You do need 'logic level conversion' to allow the PIC to control/receieve data from the device. If you bought a 'module' PCB that has the 'sensor', it might have the LLC parts on it. The datasheet should say ....
As it is an I2C device, download PCMPs I2C scanner program, located in the 'code library' here.
Run it to confirm the PIC can 'see' the BME280 device. If found, it's device address will be sent to the PC.
You should always run the 'scanner' program for every I2C device.
Jay |
but still i can't read any value in the function.. the function gives error.. can u fix it? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 03, 2020 11:41 am |
|
|
Post your printf line of code. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Tue Nov 03, 2020 1:05 pm |
|
|
You would normally want the #use I2c line, befire you load the bme
code. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 03, 2020 1:37 pm |
|
|
The bme280.c driver has it's own #use i2c() line in it. The line posted
by akay is not needed. At least, this is true for the bme driver supplied
with CCS vs. 5.096.
But there's another problem I didn't mention before. If I compile akay's
program with CCS vs. 5.096 for the 16F877A that he is using, I get this error:
Quote: |
*** Error 71 "C:\...\Projects\PCM_Test\pcm_test.c" Line 37(1,2): Out of ROM, A segment or the program is too large bme280_get_temperature
Seg 00004-007FF, 0303 left, need 00AE5
Seg 00800-00FFF, 0800 left, need 00AE5
Seg 01000-017FF, 0800 left, need 00AE5
Seg 01800-01FFF, 0800 left, need 00AE5
Seg 00000-00003, 0000 left, need 00AE5 Reserved
1 Errors, 0 Warnings.
Build Failed. |
Maybe he's using some earlier version of the compiler. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Wed Nov 04, 2020 12:56 am |
|
|
So basically the code is too big for his chip... |
|
|
jaka
Joined: 04 May 2014 Posts: 36 Location: Finland
|
|
Posted: Wed Nov 04, 2020 2:38 am |
|
|
I have used the bme280.c driver with PIC16F chips. The problem can come from the memory segment sizes, and not from the total ROM size.
Usually it helps to add #separate directives to the bme280.c before the functions
Code: | static signed int32 _bme280_compensate_T_int32(signed int32 adc_T)
static unsigned int32 _bme280_compensate_P_int32(signed int32 adc_P)
static unsigned int32 _bme280_compensate_H_int32(signed int32 adc_H)
|
However, I have been using the enhanced core 16F1xxx chips so perhaps this doesn't help with the 16F877A.
I can also provide a .diff patch file for the bme280.c which I have succesfully used with PIC16F1xxx and recent compiler versions. I can post it here if you think it doesn't violate forum rules (it doesn't reveal too many lines of the original code). |
|
|
akay
Joined: 29 Sep 2020 Posts: 17
|
|
Posted: Wed Nov 04, 2020 7:17 am |
|
|
i get this error too.. i m using 5.076 version.. i didnt compile with 16f877a ..i also have the same problem with the bmp180 driver. i am giving up.. |
|
|
akay
Joined: 29 Sep 2020 Posts: 17
|
|
Posted: Wed Nov 04, 2020 7:30 am |
|
|
i'd like to say that when I try with other drivers, i dont see these mistakes.. for example Bmp085 and bmp180 drivers are almost the same.. i was working with bmp085 driver before the bmp180 driver came to ccs and it worked very well.. there's an another problem i don't understand..
that s my simple code
Code: | #include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NODEBUG
#define use_portb_lcd TRUE
#use delay(clock = 8000000)
#include <lcd.c>
#include <BMp180.c>
#use i2c(master, sda=PIN_c4, scl=PIN_c3)
int16 Temp;
int16 press;
int16 alt;
void main()
{
lcd_init();
bmp180_init() ;
DELAY_MS(25);
while(TRUE)
{
bmp180_read(BMP180_MODE_STANDARD, press, temp, alt) ;
delay_ms(100);
lcd_gotoxy(1,2);
printf(lcd_putc," %d" press);
delay_ms(20);
}
}
|
and these mistakes
>>> Unsigned variable is never less then zero (in the driver code mistake)
>>> Condition always false
*** Error 114 "bmp180example.c" line38(23,28): Print format type is invalid::
Code: | ///////////////////////////////////////////////////////////////////////////
//// BMP180 BAROMETER DRIVER ////
//// ////
//// Driver for Bosch BMP180 digital pressure sensor. ////
//// ////
//// bmp180_init() ////
//// Initiliazes driver to communicate with sensor. ////
//// ////
//// bmp180_read(mode, *pressure, *temp, *alt) ////
//// Reads sensor values and saves them to the *pressure, *temp ////
//// and *alt pointers. 'mode' is the resolution mode, see ////
//// bmp180_mode_t for a list of valid values. *temp is read in ////
//// degrees C, *pressure is read in Pascals (Pa), and *alt is ////
//// calculated in meters (m). ////
//// ////
//// BMP180_NO_ALTITUDE ////
//// If #defined, the bmp180_updateValues() function will not ////
//// read and populate the pressure value. This is useful for ////
//// devices with small memory footprint that cannot fit the ////
//// math required. |
typedef enum
{
BMP180_MODE_LOW_POWER = 0,
BMP180_MODE_STANDARD = 1,
BMP180_MODE_HIGH_RESOLUTION = 2,
BMP180_MODE_ULTRA_HIGH_RESOLUTION = 3
} bmp180_mode_t;
Code: | void bmp180_read(bmp180_mode_t mode, signed int32 *pPressure,
signed int32 *pTemperature, signed int32 *pAltitude)
{
union
{
unsigned int8 b[4];
unsigned int16 w[2];
signed int32 dw;
} scr32;
signed int32 rawTemp=0;
signed int32 pressure=0;
if (pTemperature)
{
//WRITE 0X2E INTO REG 0XF4,WAIT 4.5MS
bmp180_write(BMP180_REG_MEASURE_CTL,BMP180_VAL_TEMP_CTL);
delay_us(4500);
//READ REG 0XF6 AND 0XF7
rawTemp=bmp180_read16(BMP180_REG_MSB);
*pTemperature = bmp180_calculateTemperature(rawTemp);
}
| |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 04, 2020 8:51 am |
|
|
akay wrote: |
printf(lcd_putc," %d" press);
*** Error 114 "bmp180example.c" line38(23,28): Print format type is invalid::
|
I told you how to fix the printf format type error in this post.
You ignored my advice.
http://www.ccsinfo.com/forum/viewtopic.php?t=59035&start=3
I said:
Quote: |
Read the CCS manual for printf. If you want to print signed numbers
larger than int8, you need to use "%ld". Put the letter 'L' in front of the 'd'. |
The 2nd problem with the printf line is that you have left off the comma
after the "%d". You have to read the CCS manual and do what it says.
The correct line is like this:
Code: | printf(lcd_putc," %ld", press); |
Regarding your errors with this other driver:
Post a link to the website where you got the driver. |
|
|
|
|
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
|