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
 BMP085 Pressure Sensor Goto page 1, 2  Next
Author Message
ajt

Joined: 07 Sep 2003
Posts: 110

BMP085 Pressure Sensor
Posted: Fri Aug 17, 2012 12:25 pm

After spending a lot of time trying to convert integer arithmetic Arduino driver code for this device to CCS, I gave up and wrote my own integer based driver. Both of these exercises were basically a waste of time because there are too many issues in data type differences and overflow, etc. problems with the integer based math.

The following driver is all floating point and works well. Usage is shown in the opening comments. A test program follows.

Please post any improvements or corrections.

(Use any of this work as you wish but you assume all risk in doing so.)

Al Testani

A test program using the driver follows:

 Code: #include <18LF2420.h> #device adc=16 #FUSES NOWDT, WDT128, H4, NOFCMEN, NOIESO, NOBROWNOUT, NOPBADEN, NOLPT1OSC, NOSTVREN, NOLVP, NOXINST // 4MHz crystal #use delay(clock=16000000) #use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, stop=1, errors) #include "./BMP085.c" // Pin Definitions #define YEL_LED         PIN_B3 #define SCL             PIN_C3  #define SDA             PIN_C4  #define TX              PIN_C6 #define RX              PIN_C7 // Macros #define set(x) output_high(x) #define clr(x) output_low(x) //---------------------------------------------- void main() //---------------------------------------------- { float Tf, P_inHg; float T_Cent; float P_mBar; int16 tp, tt;    setup_timer_0(T0_INTERNAL|T0_DIV_4); // 1 usec resolution    bmp085Calibration();    while(true)    {       set(YEL_LED);       set_timer0(0);             T_Cent = BMP085Temperature();       tt= get_timer0();       P_mBar = BMP085Pressure(false);   // skips required temp reading since already done above       tp = get_timer0() - tt;       printf("Temperature (C):  %.1g\r\n", T_Cent);       printf("Pressure (mBar):  %0.2g\r\n\n", P_mBar);       Tf = ((9.0/5.0)*T_Cent) + 32.0;       printf("Temperature (F):  %.1g\r\n", Tf);       P_inHg = (0.0295301) * P_mBar;       printf("Pressure (inHg):  %.2g\r\n\n", P_inHg);       printf("Processing time: \r\n");       printf("  Temperature = %Lu  (usec)\r\n", tt);       printf("  Pressuure   = %Lu (usec)\r\n", tp);       printf("------------------------------\r\n");             clr(YEL_LED);       delay_ms(1000);    } }

_________________
Al Testani
Lykos1986

Joined: 26 Nov 2005
Posts: 68

 Posted: Wed Apr 17, 2013 4:54 am Hi! Have you got any update about this driver? I am trying to use it but without success! It always replies back with -9 for the temperature and 247.6 for the pressure. At my code I am using: ... #include "./BMP085.c" ... bmp085Calibration(); ... T_Cent = BMP085Temperature(); P_mBar = BMP085Pressure(false); ... And then I am printing the values. The I2C pins are the correct ones but I am always having the same values Any help?
ajt

Joined: 07 Sep 2003
Posts: 110

 Posted: Wed Apr 17, 2013 7:45 am The code is the latest revision and from the code snippet you sent should work. However... I can't help at all since I don't know what PIC you are using, what the hardware schematic looks like, or what version of the compiler you are using. Does the code (unmodified) I provided including the test program work properly on your hardware? I will gladly try to help but you will have to provide much more information._________________Al Testani
Lykos1986

Joined: 26 Nov 2005
Posts: 68

 Posted: Wed Apr 17, 2013 10:48 am Actually I am using a PIC24F32KA304 #include "24F32KA304.h" and for the fuses I have: #FUSES NOWRTB, NOBSS, NOWDT, NOBROWNOUT, NOLVR, NOPUT, MCLR, ICSP2, NODEBUG, NODSWDT, NOWRT, NOPROTECT, NOIESO, PR, HS, NOCKSFSM, ALTI2C Otherwise my code is almost the same. As for the hardware part, I am using 4.7K Pull-Up resistors at the I2C pins, EOC and XCLR pins unconnected and power pins connected to the power with 100nF decoupling capacitors I was trying also to use the SLOW configuration of I2C incase that the speed was the problem but still nothing... Do you thing it is a problem with the Fuses? I will try your code without any modifications as well and I will let you know
ajt

Joined: 07 Sep 2003
Posts: 110

Posted: Wed Apr 17, 2013 11:04 am

Make sure you have a #use i2c statement in your code in one place. The following is the default in the BMP085.c file. Obviously, change it to the pins you are using:

 Code: #use i2c(master, sda=PIN_C4, scl=PIN_C3, FAST, FORCE_HW)

If you are not using the I2C peripheral then you don't want the FORCE_HW switch but I don't know if my code and/or the BMP085 would would work with software I2C. It should but I never tested it.

In terms of fuses, I don't use that PIC so don't know but you might want to check if your oscillator is set up properly.
_________________
Al Testani
Lykos1986

Joined: 26 Nov 2005
Posts: 68

 Posted: Wed Apr 17, 2013 12:11 pm Hmmm, I am using your example and I am having a few interesting results. If I use the: #use i2c(master, sda=PIN_B2, scl=PIN_B3, FAST, FORCE_SW) it replies back with: Temperature (C): 12.7 Pressure (mBar): 544347.31 If I use the: #use i2c(master, sda=PIN_B2, scl=PIN_B3, FAST, FORCE_HW) it replies back with: Temperature (C): -9 Pressure (mBar): 247.6 Of course, the results are not changing even if I gently try to heat the sensor. I've use also the SLOW instead of FAST as well but I am having exactly the same results. Probably is something wrong with the sensor...
ajt

Joined: 07 Sep 2003
Posts: 110

 Posted: Wed Apr 17, 2013 12:30 pm Maybe you should use the ICD1 or ICD2 switch in your #USE i2c statement since your PIC has two I2C hardware peripherals. I don't know if the compiler sets the correct hardware by specifying the pins only. You could look is the LST file to see what is really getting set up._________________Al Testani
Lykos1986

Joined: 26 Nov 2005
Posts: 68

 Posted: Thu Apr 18, 2013 3:10 am It is not about the I2C1 or I2C2. I just connect a USB logic analyser and it seems that the communication is more than perfect! I am having good timings, ACT conditions and everything else related to a good I2C master-slave communication. Furthermore I was checking with the datasheet and everything are as suppose to be! In other words your driver if OK! I am 99% sure that the problem is with the BMP085 sensor itself! You have to read two register values for the temperature and three register values for the pressure (plus the 11 calibration coefficients from the EEPROM only at the beginning). And then you perform the calculations at the code/driver It seems that the two temperature registers are giving back always 0xFF and 0xFF and the three pressure registers are giving back always 0x00, 0x00 and 0x00. No matter if I heat the sensor etc So, I think it is a problematic sensor and nothing more! What to expect when this sensor is from eBay for 3.5\$ with free shipping!!!
ajt

Joined: 07 Sep 2003
Posts: 110

 Posted: Thu Apr 18, 2013 10:20 am I received a notification in mid-Feb. that the BMP085 is at EOL and now obsolete. There are still some left in distribution and places like eBay. The BMP085 is not recommended for new designs. The Bosch-Sensortec website no longer lists the BMP085, just the BMP180 and BMP280. According to the BMP180 datasheet it is the replacement for the BMP085. Unfortunately, it has a different footprint so cannot go into existing designs. From a quick review of the registers and operation of the interface I believe the BMP085 driver code will work as it is except there is now a 5th resolution mode that isn't supported in my code. I need to get some samples of the BMP180 and test them out._________________Al Testani
Lykos1986

Joined: 26 Nov 2005
Posts: 68

 Posted: Thu Apr 18, 2013 12:47 pm Good to letting me know ajt! I will try to get samples from the BMP180 as well...
ajt

Joined: 07 Sep 2003
Posts: 110

 BMP180 Driver Posted: Mon May 20, 2013 3:18 pm I tested the BMP180 with the exact driver code and example for the BMP085 previously posted and it works fine._________________Al Testani
Lykos1986

Joined: 26 Nov 2005
Posts: 68

 Posted: Wed May 22, 2013 2:17 am Good news!!! I will try to source a BMP180 and make some experiments with it!
lazuribicci

Joined: 06 Feb 2010
Posts: 10

integer library
Posted: Tue Jul 30, 2013 2:00 am

Dear friends,

I have tested above library, but I cannot read pressure, however temperature seems good. I have researched step by step and I found faulty in calibration coefficient routine. First value, ac1, comes wrong. It should be 7000-8000 but it gives 12. So I read it again after md coefficient. It seems everything good.

BTW, I prepare a new integer library for BMP085.

I hope it helps some people.

Fatih GENC

ajt

Joined: 07 Sep 2003
Posts: 110

Re: integer library
Posted: Tue Jul 30, 2013 10:06 am

 lazuribicci wrote: I have tested above library, but I cannot read pressure, however temperature seems good. I have researched step by step and I found faulty in calibration coefficient routine. First value, ac1, comes wrong. It should be 7000-8000 but it gives 12. So I read it again after md coefficient. It seems everything good.

This library has been successfully used for some time. Your "fix" for the ac1 coefficient error indicates a hardware problem in your setup or something in your other code that is causing the first read of the device to be in error. I suggest you find the root cause of the problem and fix that vs adding a second read as you have.

Thanks for the integer version of the library.
_________________
Al Testani
waynewy

Joined: 16 Sep 2013
Posts: 4
Location: United States

 Posted: Mon Sep 16, 2013 9:23 am Just a quick question, where did you get the i2c library in order to use i2c_start(), i2c_write(), etc? Thanks!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 6 HoursGoto page 1, 2  Next Page 1 of 2

 Jump to: Select a forum Software----------------General CCS C DiscussionCode LibraryEZ App Lynx Hardware----------------CCS ICD / Mach X / Load-n-Go
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