{"id":4469,"date":"2026-05-23T07:46:42","date_gmt":"2026-05-23T07:46:42","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=4469"},"modified":"2026-05-23T07:47:06","modified_gmt":"2026-05-23T07:47:06","slug":"interfacing-bmp180-with-stm32-part-1-firmware-development","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=4469","title":{"rendered":"Interfacing BMP180 with STM32 Part 2 : Firmware Development"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-1024x572.png\" alt=\"\" class=\"wp-image-4470\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-1024x572.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-300x167.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-768x429.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-1150x642.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-750x419.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-400x223.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1-250x141.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/Gemini_Generated_Image_ciipxkciipxkciip-1.png 1376w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In Part 2, we dive into the core firmware development by establishing\u00a0$I^2C$\u00a0communication to read the factory-calibrated coefficients and raw data from the BMP180 sensor. You will learn how to implement the datasheet&#8217;s specific compensation algorithms to accurately calculate and stream real-time temperature and pressure values via UART.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Firmware Development.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. Firmware Development.<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>We start first by creating new source and header files with name of BMP180.c and BMP180.h respectively.<\/p>\n\n\n\n<p>Open BMP180.h header file.<\/p>\n\n\n\n<p>First, the sensor has sampling time per the datasheet as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"566\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-1024x566.png\" alt=\"\" class=\"wp-image-4471\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-1024x566.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-300x166.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-768x425.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-1536x850.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-1150x636.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-750x415.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-400x221.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57-250x138.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-04-57.png 2014w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We need to define these values in the header, we can use enumeration to do that as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">typedef enum\n{\n\tOSS0=0,\n\tOSS1=1,\n\tOSS2=2,\n\tOSS3=3\n}OSS;<\/pre><\/div>\n\n\n\n<p>Next, we define the function to initialize the sensor as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void BMP180_init();<\/pre><\/div>\n\n\n\n<p>Next, a function that updates the sensor data as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void update_BMP180(OSS OSS);<\/pre><\/div>\n\n\n\n<p>The function takes oversampling a parameter.<\/p>\n\n\n\n<p>Finally, function that should return the measured temperature and pressure as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">float get_temperature(void);\nfloat get_pressure(void);<\/pre><\/div>\n\n\n\n<p>Hence, the entire header file as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef INC_BMP180_H_\n#define INC_BMP180_H_\n\n\ntypedef enum\n{\n\tOSS0=0,\n\tOSS1=1,\n\tOSS2=2,\n\tOSS3=3\n}OSS;\n\nvoid BMP180_init();\n\nvoid update_BMP180(OSS OSS);\nfloat get_temperature(void);\nfloat get_pressure(void);\n\n\n#endif<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, open BMP180.c source file.<\/p>\n\n\n\n<p>In the source file, we shall start by including the following header files:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;BMP180.h&quot;\n\n#include &quot;i2c.h&quot;\n\n#include &quot;math.h&quot;<\/pre><\/div>\n\n\n\n<p>Next, we define the address of the sensor. <br>From the datasheet of the sensor, we can find the address is 0x77 as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"727\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-1024x727.png\" alt=\"\" class=\"wp-image-4472\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-1024x727.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-300x213.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-768x545.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-1536x1090.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-2048x1454.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-1150x816.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-750x532.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-400x284.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-12-26-250x177.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Hence, we can define as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define BMP_180_add 0x77&lt;&lt;1<\/pre><\/div>\n\n\n\n<p>We shift to left by 1 to handle read\/write operation by the i2c library.<\/p>\n\n\n\n<p>Next, variable to store the calibration variables as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"333\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-1024x333.png\" alt=\"\" class=\"wp-image-4473\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-1024x333.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-300x98.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-768x250.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-1536x500.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-2048x666.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-1150x374.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-750x244.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-400x130.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-17-55-250x81.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">short AC1,AC2,AC3,B1,B2,MB,MC,MD;\nunsigned short AC4,AC5,AC6;<\/pre><\/div>\n\n\n\n<p>Declare a buffer of 22 bytes to store the calibration data as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t eeprom_data[22];<\/pre><\/div>\n\n\n\n<p>Next, define the address of the calibration values that stored in the EEPROM of BMP180:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"518\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-1024x518.png\" alt=\"\" class=\"wp-image-4475\" style=\"width:840px;height:auto\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-1024x518.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-300x152.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-768x388.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-1536x776.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-1150x581.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-750x379.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-400x202.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1-250x126.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-21-07-1.png 1856w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define EEPROM_St_add 0xAA<\/pre><\/div>\n\n\n\n<p>Next, declare buffers to store the incoming bytes from the sensor and uncompensated pressure and temperature values as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">long UT,UP;\nuint8_t data_tem[2],data_pres[3];<\/pre><\/div>\n\n\n\n<p>Next, variable to handle the calculation of the temperature and humidity as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">long X1 = 0;\nlong X2 = 0;\nlong X3 = 0;\nlong B3 = 0;\nlong B5 = 0;\nunsigned long B4 = 0;\nlong B6 = 0;\nunsigned long B7 = 0;\nlong Press = 0;<\/pre><\/div>\n\n\n\n<p>Next, declare a data structure to hold temperature and pressure values as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">typedef struct\n{\n\tfloat temperature;\n\tfloat pressure;\n}BMP180Sensor_t;\n\nBMP180Sensor_t BMP180;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, for sensor initialization, all we need is to read the calibration data as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void BMP180_init(void)\n{\n\tHAL_I2C_Mem_Read(&amp;hi2c1,BMP_180_add,EEPROM_St_add,1,eeprom_data,22,10);\n\n\tAC1=(eeprom_data[0]&lt;&lt;8)+eeprom_data[1];\n\tAC2=(eeprom_data[2]&lt;&lt;8)+eeprom_data[3];\n\tAC3=(eeprom_data[4]&lt;&lt;8)+eeprom_data[5];\n\tAC4=(eeprom_data[6]&lt;&lt;8)+eeprom_data[7];\n\tAC5=(eeprom_data[8]&lt;&lt;8)+eeprom_data[9];\n\tAC6=(eeprom_data[10]&lt;&lt;8)+eeprom_data[11];\n\tB1=(eeprom_data[12]&lt;&lt;8)+eeprom_data[13];\n\tB2=(eeprom_data[14]&lt;&lt;8)+eeprom_data[15];\n\tMB=(eeprom_data[16]&lt;&lt;8)+eeprom_data[17];\n\tMC=(eeprom_data[18]&lt;&lt;8)+eeprom_data[19];\n\tMD=(eeprom_data[20]&lt;&lt;8)+eeprom_data[21];\n\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, for update the sensor data:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void update_BMP180(OSS OSS)<\/pre><\/div>\n\n\n\n<p>To read the uncompensated temperature value:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1010\" height=\"346\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-1.png\" alt=\"\" class=\"wp-image-4476\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-1.png 1010w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-1-300x103.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-1-768x263.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-1-750x257.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-1-400x137.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-1-250x86.png 250w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<p><br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t datatowrite = 0x2E;\n\n\tHAL_I2C_Mem_Write(&amp;hi2c1,BMP_180_add,0xF4,1,&amp;datatowrite,1,10);\n\n\tHAL_Delay(5);\n\n\tHAL_I2C_Mem_Read(&amp;hi2c1,BMP_180_add,0xF6,1,data_tem,2,10);\n\n\tUT=(data_tem[0]&lt;&lt;8)+data_tem[1];<\/pre><\/div>\n\n\n\n<p>Next, get the over sampling value passed by the user as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t oss;\nswitch (OSS)\n{\n  case OSS0: oss=0; break;\n  case OSS1: oss=1; break;\n  case OSS2: oss=2; break;\n  case OSS3: oss=3; break;\n  default :  oss=0; break;\n}<\/pre><\/div>\n\n\n\n<p>Next, to read the uncompensated pressure value:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1010\" height=\"346\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-2.png\" alt=\"\" class=\"wp-image-4477\" style=\"width:840px;height:auto\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-2.png 1010w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-2-300x103.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-2-768x263.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-2-750x257.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-2-400x137.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/image-2-250x86.png 250w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">datatowrite=0x34+(oss&lt;&lt;6);\n\nHAL_I2C_Mem_Write(&amp;hi2c1,BMP_180_add,0xF4,1,&amp;datatowrite,1,10);\n\nswitch (OSS)\n{\n  case OSS0: HAL_Delay(5);  break;\n  case OSS1: HAL_Delay(8);  break;\n  case OSS2: HAL_Delay(14); break;\n  case OSS3: HAL_Delay(26); break;\n  default  : HAL_Delay(5);  break;\n}\n\nHAL_I2C_Mem_Read(&amp;hi2c1,BMP_180_add,0xF6,1,data_pres,3,10);\n\nUP=((data_pres[0]&lt;&lt;16)+(data_pres[1]&lt;&lt;8)+(data_pres[2]))&gt;&gt;(8-oss);<\/pre><\/div>\n\n\n\n<p>Now, according to the datasheet, the calculation as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"679\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26-679x1024.png\" alt=\"\" class=\"wp-image-4478\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26-679x1024.png 679w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26-199x300.png 199w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26-768x1159.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26-750x1131.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26-400x603.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26-250x377.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_10-34-26.png 924w\" sizes=\"(max-width: 679px) 100vw, 679px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Hence, the calculation as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/calculate temperature\n\tlong x1=((UT-AC6) * (AC5\/(pow(2,15))));\n\tlong x2= ((MC)*(pow(2,11)))\/(x1+MD);\n\tlong B5= (x1+x2);\n\tBMP180.temperature= ((B5+8)\/(pow(2,4)))\/10;\n\n\t\/\/calculate pressure\n\tB6 = B5-4000;\n\tX1 = (B2 * (B6*B6\/(pow(2,12))))\/(pow(2,11));\n\tX2 = AC2*B6\/(pow(2,11));\n\tX3 = X1+X2;\n\tB3 = (((AC1*4+X3)&lt;&lt;oss)+2)\/4;\n\tX1 = AC3*B6\/pow(2,13);\n\tX2 = (B1 * (B6*B6\/(pow(2,12))))\/(pow(2,16));\n\tX3 = ((X1+X2)+2)\/pow(2,2);\n\tB4 = AC4*((unsigned long)(X3+32768))\/(pow(2,15));\n\tB7 = ((unsigned long)UP-B3)*(50000&gt;&gt;oss);\n\tif (B7&lt;0x80000000) {Press = (B7*2)\/B4;}\n\telse {Press = (B7\/B4)*2;}\n\tX1 = (Press\/(pow(2,8)))*(Press\/(pow(2,8)));\n\tX1 = (X1*3038)\/(pow(2,16));\n\tX2 = (-7357*Press)\/(pow(2,16));\n\tPress = Press + (X1+X2+3791)\/(pow(2,4));\n\tBMP180.pressure = Press;<\/pre><\/div>\n\n\n\n<p>Finally, the functions that return the temperature and pressure as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">float get_temperature(void)\n{\n\treturn BMP180.temperature;\n}\n\nfloat get_pressure(void)\n{\n\treturn BMP180.pressure;\n}<\/pre><\/div>\n\n\n\n<p>Hence, the entire BMP180.c source file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;BMP180.h&quot;\n\n#include &quot;i2c.h&quot;\n\n#include &quot;math.h&quot;\n\n#define BMP_180_add 0x77&lt;&lt;1\n\n#define EEPROM_St_add 0xAA\n\nuint8_t eeprom_data[22];\n\nshort AC1,AC2,AC3,B1,B2,MB,MC,MD;\nunsigned short AC4,AC5,AC6;\n\nlong UT,UP;\nuint8_t data_tem[2],data_pres[3];\n\n\nlong X1 = 0;\nlong X2 = 0;\nlong X3 = 0;\nlong B3 = 0;\nlong B5 = 0;\nunsigned long B4 = 0;\nlong B6 = 0;\nunsigned long B7 = 0;\nlong Press = 0;\n\ntypedef struct\n{\n\tfloat temperature;\n\tfloat pressure;\n}BMP180Sensor_t;\n\nBMP180Sensor_t BMP180;\n\n\n\nvoid BMP180_init(void)\n{\n\tHAL_I2C_Mem_Read(&amp;hi2c1,BMP_180_add,EEPROM_St_add,1,eeprom_data,22,10);\n\n\tAC1=(eeprom_data[0]&lt;&lt;8)+eeprom_data[1];\n\tAC2=(eeprom_data[2]&lt;&lt;8)+eeprom_data[3];\n\tAC3=(eeprom_data[4]&lt;&lt;8)+eeprom_data[5];\n\tAC4=(eeprom_data[6]&lt;&lt;8)+eeprom_data[7];\n\tAC5=(eeprom_data[8]&lt;&lt;8)+eeprom_data[9];\n\tAC6=(eeprom_data[10]&lt;&lt;8)+eeprom_data[11];\n\tB1=(eeprom_data[12]&lt;&lt;8)+eeprom_data[13];\n\tB2=(eeprom_data[14]&lt;&lt;8)+eeprom_data[15];\n\tMB=(eeprom_data[16]&lt;&lt;8)+eeprom_data[17];\n\tMC=(eeprom_data[18]&lt;&lt;8)+eeprom_data[19];\n\tMD=(eeprom_data[20]&lt;&lt;8)+eeprom_data[21];\n\n}\n\nvoid update_BMP180(OSS OSS)\n{\n\tuint8_t datatowrite = 0x2E;\n\n\tHAL_I2C_Mem_Write(&amp;hi2c1,BMP_180_add,0xF4,1,&amp;datatowrite,1,10);\n\n\tHAL_Delay(5);\n\n\tHAL_I2C_Mem_Read(&amp;hi2c1,BMP_180_add,0xF6,1,data_tem,2,10);\n\n\tUT=(data_tem[0]&lt;&lt;8)+data_tem[1];\n\n\tuint8_t oss;\n\t\tswitch (OSS)\n\t\t{\n\t\t\tcase OSS0: oss=0; break;\n\t\t\tcase OSS1: oss=1; break;\n\t\t\tcase OSS2: oss=2; break;\n\t\t\tcase OSS3: oss=3; break;\n\t\t\tdefault :  oss=0; break;\n\t\t}\n\n\tdatatowrite=0x34+(oss&lt;&lt;6);\n\n\tHAL_I2C_Mem_Write(&amp;hi2c1,BMP_180_add,0xF4,1,&amp;datatowrite,1,10);\n\n\tswitch (OSS)\n\t\t{\n\t\t\tcase OSS0: HAL_Delay(5);  break;\n\t\t\tcase OSS1: HAL_Delay(8);  break;\n\t\t\tcase OSS2: HAL_Delay(14); break;\n\t\t\tcase OSS3: HAL_Delay(26); break;\n\t\t\tdefault  : HAL_Delay(5);  break;\n\t\t}\n\n\tHAL_I2C_Mem_Read(&amp;hi2c1,BMP_180_add,0xF6,1,data_pres,3,10);\n\n\tUP=((data_pres[0]&lt;&lt;16)+(data_pres[1]&lt;&lt;8)+(data_pres[2]))&gt;&gt;(8-oss);\n\n\t\/\/calculate temperature\n\tlong x1=((UT-AC6) * (AC5\/(pow(2,15))));\n\tlong x2= ((MC)*(pow(2,11)))\/(x1+MD);\n\tlong B5= (x1+x2);\n\tBMP180.temperature= ((B5+8)\/(pow(2,4)))\/10;\n\n\t\/\/calculate pressure\n\tB6 = B5-4000;\n\tX1 = (B2 * (B6*B6\/(pow(2,12))))\/(pow(2,11));\n\tX2 = AC2*B6\/(pow(2,11));\n\tX3 = X1+X2;\n\tB3 = (((AC1*4+X3)&lt;&lt;oss)+2)\/4;\n\tX1 = AC3*B6\/pow(2,13);\n\tX2 = (B1 * (B6*B6\/(pow(2,12))))\/(pow(2,16));\n\tX3 = ((X1+X2)+2)\/pow(2,2);\n\tB4 = AC4*((unsigned long)(X3+32768))\/(pow(2,15));\n\tB7 = ((unsigned long)UP-B3)*(50000&gt;&gt;oss);\n\tif (B7&lt;0x80000000) {Press = (B7*2)\/B4;}\n\telse {Press = (B7\/B4)*2;}\n\tX1 = (Press\/(pow(2,8)))*(Press\/(pow(2,8)));\n\tX1 = (X1*3038)\/(pow(2,16));\n\tX2 = (-7357*Press)\/(pow(2,16));\n\tPress = Press + (X1+X2+3791)\/(pow(2,4));\n\tBMP180.pressure = Press;\n\n}\n\nfloat get_temperature(void)\n{\n\treturn BMP180.temperature;\n}\n\nfloat get_pressure(void)\n{\n\treturn BMP180.pressure;\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, open main.c source file.<\/p>\n\n\n\n<p>We start by including the bmp180 header file as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;BMP180.h&quot;<\/pre><\/div>\n\n\n\n<p>In user code begin PV, declare temperature and pressure variables:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">float pressure, temperature;<\/pre><\/div>\n\n\n\n<p>In user code begin 2 in main function, initialize the sensor:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">BMP180_init();<\/pre><\/div>\n\n\n\n<p>In while 1 loop, in user code begin 3:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update the sensor.<\/li>\n\n\n\n<li>Get the temperature and pressure.<\/li>\n\n\n\n<li>Print the temperature and pressure.<\/li>\n\n\n\n<li>Wait for 200ms between each reading.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">update_BMP180(OSS3);\ntemperature=get_temperature();\npressure=get_pressure();\n\nprintf(&quot;Temperature = %0.4f and Pressure =%0.4f\\r\\n&quot;,temperature,pressure);\n\nHAL_Delay(200);<\/pre><\/div>\n\n\n\n<p>Thats all for the firmware.<\/p>\n\n\n\n<p>Save, build the project and run it as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"34\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-1024x34.png\" alt=\"\" class=\"wp-image-4349\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-1024x34.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-300x10.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-768x26.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-1536x51.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-1150x38.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-750x25.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-400x13.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1-250x8.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/04\/image-1.png 1986w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You may download the project from <a href=\"https:\/\/github.com\/hussamaldean\/Embedded-Expert-Post-Projects\/tree\/main\/Projects\/BMP180_STM32\" data-type=\"link\" data-id=\"https:\/\/github.com\/hussamaldean\/Embedded-Expert-Post-Projects\/tree\/main\/Projects\/BMP180_STM32\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Results:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>Open your terminal application, set the baudrate to 115200 and you should get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"707\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-1024x707.png\" alt=\"\" class=\"wp-image-4479\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-1024x707.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-300x207.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-768x530.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-1536x1060.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-1150x794.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-750x518.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-400x276.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29-250x173.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/05\/2026-05-23_09-57-29.png 1866w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Part 2, we dive into the core firmware development by establishing\u00a0$I^2C$\u00a0communication to read the factory-calibrated coefficients and raw data from the BMP180 sensor. You will learn how to implement the datasheet&#8217;s specific compensation algorithms to accurately calculate and stream real-time temperature and pressure values via UART. In this guide, we shall cover the following: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2,11,12],"tags":[],"class_list":["post-4469","post","type-post","status-publish","format-standard","hentry","category-data-structures","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4469"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4469"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4469\/revisions"}],"predecessor-version":[{"id":4481,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4469\/revisions\/4481"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}