OpenEdv-开源电子网

 找回密码
 立即注册

扫一扫,访问微社区

正点原子新作:阿波罗STM32F767&F429&探索者STM32F4开发板&赶快来下载资料哦。

查看: 106|回复: 1

用IO模拟IIC读取BMP180,读到的UT是0,UP是65535,校准系数能够读出来,求解求解。

[复制链接]

  离线 

1

主题

2

帖子

0

精华

新手上路

Rank: 1

积分
25
金钱
25
注册时间
2017-9-30
在线时间
4 小时
发表于 2017-10-25 01:56:56 | 显示全部楼层 |阅读模式
1金钱
用原子大大的mpu6050例程的模拟IIC读取BMP180,读到的UT是0,UP是65535,校准系数能够读出来,求解求解。代码贴出来,求大神解答啊,硬件什么的应该没问题。
[C] 纯文本查看 复制代码
#include "bmp180.h"
#include "delay.h"
#include "mpuiic.h"
#include "sys.h"
#include "math.h"
#include "usart.h"
//***BMP085ê1óÃ
long  result_UT=0;
long  result_UP=0;

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;

//*********************************************************
//¶á3öBMP085Äú2¿êy¾Y,á¬Døὸö
//*********************************************************
u16 Multiple_read(u8 ST_Address)
{   
	u8 msb, lsb;
	u16 _data;
    MPU_IIC_Start();                          //Æeê¼DÅoÅ
    MPU_IIC_Send_Byte(BMP180_SlaveAddress);    //·¢Ëíé豸μØÖ·+D′DÅoÅ
	while(MPU_IIC_Wait_Ack());
    MPU_IIC_Send_Byte(ST_Address);             //·¢Ëí′æ′¢μ¥ÔaμØÖ·
	while(MPU_IIC_Wait_Ack());                                 
    MPU_IIC_Start();                          //Æeê¼DÅoÅ
    MPU_IIC_Send_Byte(BMP180_SlaveAddress+1);         //·¢Ëíé豸μØÖ·+¶áDÅoÅ
	while(MPU_IIC_Wait_Ack());                                        

    msb = MPU_IIC_Read_Byte(1);                 //BUF[0]′æ′¢                
    lsb = MPU_IIC_Read_Byte(0);                //×îoóò»¸öêy¾YDèòa»ØNOACK

    MPU_IIC_Stop();                           //í£Ö1DÅoÅ
    delay_ms(5);
    _data = msb << 8;
	_data |= lsb;	
	return _data;
}
//********************************************************************
u16 bmp180ReadTemp(void)
{

    MPU_IIC_Start();                  //Æeê¼DÅoÅ
    MPU_IIC_Send_Byte(BMP180_SlaveAddress);   //·¢Ëíé豸μØÖ·+D′DÅoÅ   BMP180_SlaveAddress  0xee	ÆøÑ1′«¸DÆ÷Æ÷¼tμØÖ·
	while(MPU_IIC_Wait_Ack());
    MPU_IIC_Send_Byte(0xF4);	// write register address
    while(MPU_IIC_Wait_Ack());
	MPU_IIC_Send_Byte(0x2E);       	// write register data for temp
    while(MPU_IIC_Wait_Ack());
	MPU_IIC_Stop();                   //·¢Ëíí£Ö1DÅoÅ
	delay_ms(50);	// max time is 4.5ms
	return Multiple_read(0xF6);
}
//*************************************************************
u16 bmp180ReadPressure(void)
{
	//u16 pressure = 0;

    MPU_IIC_Start();                   //Æeê¼DÅoÅ
    MPU_IIC_Send_Byte(BMP180_SlaveAddress);   //·¢Ëíé豸μØÖ·+D′DÅoÅ
    while(MPU_IIC_Wait_Ack());
	MPU_IIC_Send_Byte(0xF4);	          // write register address
    while(MPU_IIC_Wait_Ack());
	MPU_IIC_Send_Byte(0x34);       	  // write register data for pressure
    while(MPU_IIC_Wait_Ack());
	MPU_IIC_Stop();                    //·¢Ëíí£Ö1DÅoÅ
	delay_ms(50);    	                  // max time is 4.5ms
	
	//pressure = Multiple_read(0xF6);
	//pressure &= 0x0FFFF;
	
	return Multiple_read(0xF6);//pressure;	
}

//**************************************************************

//3õê¼»ˉBMP085£¬¸ù¾YDèòaÇë2ο¼pdf½øDDDT¸Ä**************
void Init_BMP180()
{
	MPU_IIC_Init();
	ac1 = Multiple_read(0xAA);
	ac2 = Multiple_read(0xAC);
	ac3 = Multiple_read(0xAE);
	ac4 = Multiple_read(0xB0);
	ac5 = Multiple_read(0xB2);
	ac6 = Multiple_read(0xB4);
	b1 =  Multiple_read(0xB6);
	b2 =  Multiple_read(0xB8);
	mb =  Multiple_read(0xBA);
	mc =  Multiple_read(0xBC);
	md =  Multiple_read(0xBE);
	printf("ac1:%d \r\n",ac1);
	printf("ac2:%d \r\n",ac2);
	printf("ac3:%d \r\n",ac3);
	printf("ac4:%d \r\n",ac4);
	printf("ac5:%d \r\n",ac5);
	printf("ac6:%d \r\n",ac6);
	printf("b1:%d \r\n",b1);
	printf("b2:%d \r\n",b2);
	printf("mb:%d \r\n",mb);
	printf("mc:%d \r\n",mc);
	printf("md:%d \r\n",md);
}
//***********************************************************************
void bmp180Convert()
{
	unsigned int ut=0;
	unsigned long up=0;
	long x1, x2, b5, b6, x3, b3, p;
	unsigned long b4, b7;

	ut = bmp180ReadTemp();	   // ¶áè¡Î¶è
	up = bmp180ReadPressure();  // ¶áè¡Ñ1Ç¿    return pressure;
  printf("up:%ld \r\n",up);	
	printf("ut:%d \r\n",ut);
	//*************
	x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
	x2 = ((long) mc << 11) / (x1 + md);
	b5 = x1 + x2;
	result_UT = ((b5 + 8) >> 4);
	//*************		
	b6 = b5 - 4000;
	                         // Calculate B3
	x1 = (b2 * (b6 * b6)>>12)>>11;
	x2 = (ac2 * b6)>>11;
	x3 = x1 + x2;
	b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;	
	                         // Calculate B4
	x1 = (ac3 * b6)>>13;
	x2 = (b1 * ((b6 * b6)>>12))>>16;
	x3 = ((x1 + x2) + 2)>>2;
	b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
	
	b7 = ((unsigned long)(up - b3) * (50000>>OSS));
	if (b7 < 0x80000000)
	p = (b7<<1)/b4;
	else
	p = (b7/b4)<<1;
	
	x1 = (p>>8) * (p>>8);
	x1 = (x1 * 3038)>>16;
	x2 = (-7357 * p)>>16;
	result_UP = p+((x1 + x2 + 3791)>>4);
	
}


/****************************************************************
¡¡¡¡¡¡oˉêyÃû3Æ£oBMP085_Get_Altitude			    
¡¡¡¡¡¡oˉêy1|Äü£o»ñè¡o£°Î¸ß¶èÖμ
¡¡¡¡¡¡èë¿ú2Îêy£oÎT
¡¡¡¡¡¡3ö¿ú2Îêy£oaltitude //intDí  2×Ö½ú£¬μ±Ç°o£°Î¸ß¶èÖμ
¡¡¡¡¡¡±¸ ×¢£o	 ·μ»Øμĸ߶èÖμμ¥λÎaàåÃ×£¬μ÷óÃê±Ôù»»Ëã3é′øD¡êyμÄòÔÃ×Îaμ¥λμĸ߶èÖμ
*****************************************************************/

double BMP180_Get_Altitude(long p)
{
	double  altitude;
	p=(float)p;				//»ñè¡ÆøÑ1Öμ
	altitude=44330.0*(1-pow((double)p/101325,1/5.255));  	//¸ù¾YD¾Æ¬êÖ2áìá1©μÄ1«ê½¼ÆËão£°Î¸ß¶è
	altitude*=100;	 		//×a»»3éàåÃ×μ¥λμĸ߶èÖ죬μ÷óÃê±Ôù»»Ëã3é′øD¡êyμĸ߶èÖ죬ìá¸ß¾«¶è
	return altitude;
}




[C] 纯文本查看 复制代码
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "mpu6050.h"
#include "usmart.h" 
#include "mpuiic.h"
#include "bmp180.h"



//′®¿ú1·¢Ëí1¸ö×Ö·û 
//c:òa·¢ËíμÄ×Ö·û
void usart1_send_char(u8 c)
{   	
	while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); //Ñ-»··¢Ëí,Ö±μ½·¢Ëííê±Ï   
	USART_SendData(USART1,c);  
} 

 int main(void)
{	 
	
   long  result_UT;
   long  result_UP;
	 int BMP180_ID;
	 double Altitude;
	 
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	 //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
	uart_init(9600);	 	//′®¿ú3õê¼»ˉÎa500000
	delay_init();	//Ñóê±3õê¼»ˉ 
	usmart_dev.init(72);		//3õê¼»ˉUSMART
	 Init_BMP180();
	
 	while(1)
  {
		 BMP180_ID = MPU_Read_Byte(0xd0);      //¶áè¡IDμØÖ·
		 printf("BMP180_ID:0x%x \r\n",BMP180_ID);
		 bmp180Convert();         
     Altitude=BMP180_Get_Altitude(result_UP);		
		 printf("Press:%.ld Pa \r\n",result_UP);          
     printf("Altitude:%lf m \r\n",Altitude); 
     printf("Temperature:%ld \r\n",result_UT);	
		
		 delay_ms(1000);
	}
}



求解答……

回复

使用道具 举报

  离线 

1

主题

2

帖子

0

精华

新手上路

Rank: 1

积分
25
金钱
25
注册时间
2017-9-30
在线时间
4 小时
 楼主| 发表于 2017-10-25 02:01:28 | 显示全部楼层
压强和温度都是0,而高度就乱七八糟了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则




QQ|联系我们|手机版|官方淘宝店|新浪微博|微信公众平台|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2017-11-22 18:52

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表
/* */