资源简介
已经调试好的压力传感器bmp180程序,测试成功 温度和压力都准确。
单片机STM32F100
在主程序中#include "bmp180.h"
定义IO口:
#define I2C_SDA_PIN 7
#define I2C_SCL_PIN 6
#define I2C_GPIO GPIOB
gpio_init(I2C_GPIO,I2C_SDA_PIN, GPIO_Mode_AF_OD | GPIO_Speed_50MHz);
gpio_init(I2C_GPIO,I2C_SCL_PIN, GPIO_Mode_AF_OD | GPIO_Speed_50MHz);
定义全局变量:
s32 bmp180_temp,bmp180_presure; //bmp180
主程序调用:
test_pressure_main();
即得到
温度bmp180_temp值
压力bmp180_presure值
代码片段和文件信息
#include “bmp180.h“
short ac1;
short ac2;
short ac3;
unsigned short ac4;
unsigned short ac5;
unsigned short ac6;
short b1;
short b2;
short mb;
short mc;
short md;
/* Private function prototypes -----------------------------------------------*/
void Delay(u32 nCount);
//void GPIO_Configuration(void);
extern void I2C_delay(uint32_t cnt);
/**
* @brief Main program
* @param None
* @retval None
*/
////Read calibration data from the E2PROM of the BMP180
////read out E2PROM registers 16 bit MSB first
void temp_calibration(void)
{
uint8_t buf[2];
I2C_Read(Open_I2CADDR_24LC020xaabuf 2);
ac1 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xacbuf 2);
ac2 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xaebuf 2);
ac3 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xb0buf 2);
ac4 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xb2buf 2);
ac5 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xb4buf 2);
ac6 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xb6buf 2);
b1 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xb8buf 2);
b2 = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xbabuf 2);
mb = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xbcbuf 2);
mc = buf[0] << 8 |buf[1];
I2C_Read(Open_I2CADDR_24LC020xbebuf 2);
md = buf[0] << 8 |buf[1];
////printf(“ac1=%dac2=%dac3=%dac4=%dac5=%dac6=%db1=%db2=%dmb=%dmc=%dmd=%d\r\n“ac1ac2ac3ac4ac5ac6b1b2mbmcmd);
}
void test_pressure_main(void)
{
long x1x2x3b3b5b6b7press_regpressuretemp_regtemp;
//long x1x2x3b3b5b6b7press_regpressuretemp_reg;
unsigned long b4;
//int reti;
uint8_t ReadBuffer[10];
//unsigned short ;
//unsigned int ;
char oss = 0; //这个值在读气压时可以置进寄存器
//GPIO_Configuration();
////USART_Configuration();
I2C_Configuration();
////printf(“\r\n****************************************************************\r\n“);
//while (1)
//{
////printf(“\r\n Read start \r\n“);
temp_calibration();
//read uncompensated temperature
I2C_WriteOneByte(Open_I2CADDR_24LC020xf40x2e);
I2C_delay(200000);//delay 4.5ms
//ret = I2C_Read(Open_I2CADDR_24LC020xf6ReadBuffer2);
I2C_Read(Open_I2CADDR_24LC020xf6ReadBuffer2);
temp_reg = ReadBuffer[0] << 8 | ReadBuffer[1];
////printf(“temp_reg %d \r\n“temp_reg);
//calculate true temperature
x1 = ((temp_reg - ac6) * ac5) >> 15;
x2 = ((long) mc << 11) / (x1 + md);
b5 = x1 + x2;
temp = (b5 + 8) >> 4;
bmp180_temp=temp;
////printf(“x1:%d x2:%d b5:%d temp(*0.1):%d \r\n“x1x2b5temp);
//read uncompensated pressure
//////write 0x34+(oss<<6) into reg 0xF4 wait 4.5ms
I2C_WriteOneByte(Open_I2CADDR_24LC020xf4(0x34 +(oss<<6)));
//I2C_WriteOneByte(Open_I2CADDR_24LC020xf4(0x3e + oss<<6));
//I2C_WriteOneByte(Open_I2CADDR_24LC020xf4
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5325 2014-03-24 17:51 bmp180\bmp180.c
文件 369 2014-03-24 17:53 bmp180\bmp180.h
文件 8175 2014-03-20 16:12 bmp180\bmpi2c.c
文件 2317 2014-03-24 10:57 bmp180\bmpi2c.h
目录 0 2014-03-24 17:54 bmp180
----------- --------- ---------- ----- ----
16186 5
评论
共有 条评论