WXK
2023-07-07 6c87b494401e48edc87fc0ada04858f424501656
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef __BMP390_H
#define __BMP390_H
//#include "myiic.h"
//#include "sys.h"
//#include "LCD.h"
//#include "delay.h"
#include "stdio.h"
#include "math.h"
#include "main.h"
 
 
#define BMP390_Write 0XEE
#define BMP390_Read 0xEF
#define BMP390_CMD_SOFT_RESET   0xB6
#define CHIP_ID_Addr 0x00
#define REV_ID_Addr 0x01
#define ERR_REG_Addr 0x02
#define STATUS_Addr 0x03
 
#define PSR_B2_Addr 0x06
#define PSR_B1_Addr 0x05
#define PSR_B0_Addr 0x04
 
#define TMP_B2_Addr 0x09
#define TMP_B1_Addr 0x08
#define TMP_B0_Addr 0x07
 
#define SENSORTIME_0_Addr 0x0C
#define SENSORTIME_1_Addr 0x0D
#define SENSORTIME_2_Addr 0x0E
 
#define EVENT_Addr 0x10
#define INT_CTRL_Addr 0x19
#define IF_CONF_Addr 0x1A
#define PWR_CTRL_Addr 0x1B
#define OSR_Addr 0x1C
#define ODR_Addr 0x1D
#define CONFIG_Addr 0x1F
#define CMD_Addr 0x7E
 
#define NVM_PAR_P11_Addr  0x45
#define NVM_PAR_P10_Addr  0x44
#define NVM_PAR_P9_H_Addr  0x43
#define NVM_PAR_P9_L_Addr  0x42
#define NVM_PAR_P8_Addr  0x41
#define NVM_PAR_P7_Addr  0x40
#define NVM_PAR_P6_H_Addr  0x3F
#define NVM_PAR_P6_L_Addr  0x3E
#define NVM_PAR_P5_H_Addr  0x3D
#define NVM_PAR_P5_L_Addr  0x3C
#define NVM_PAR_P4_Addr  0x3B
#define NVM_PAR_P3_Addr  0x3A
#define NVM_PAR_P2_H_Addr  0x39
#define NVM_PAR_P2_L_Addr  0x38
#define NVM_PAR_P1_H_Addr  0x37
#define NVM_PAR_P1_L_Addr  0x36
 
#define NVM_PAR_T3_Addr  0x35
#define NVM_PAR_T2_H_Addr  0x34
#define NVM_PAR_T2_L_Addr  0x33
#define NVM_PAR_T1_H_Addr  0x32
#define NVM_PAR_T1_L_Addr  0x31
 
#define Total_Number_32 4294967296.0
#define Total_Number_30 1073741824.0
#define Total_Number_29 536870912.0
#define Total_Number_24 16777216.0
#define Total_Number_20 1048576.0
#define Total_Number_16 65536.0
#define Total_Number_15 32768.0
#define Total_Number_14 16384.0
#define Total_Number_12 4096.0
#define Total_Number_8 256.0
#define Total_Number_6 64.0
#define Total_Number_5 32.0
#define Total_Number_1 2.0
 
#define Total_Number_Neg_8 0.00390625
#define Total_Number_Neg_3 0.125
 
u8 BMP390_Init(void);
u8 BMP390_Read_Byte(u8 addr);
u32 Temperature_Read(void);
u32 Pressure_Read(void);
void BMP390_Write_Byte(u8 addr,u8 data);
void Parameter_Reading(int *Pressure_Para,int *Temperature_Para);
double Correcting_Temperature(u32 Temperature,int *Temperature_Para);
double Correcting_Pressure(u32 Pressure,int *Pressure_Para,double Corr_Temperature);
 
////IO·½ÏòÉèÖÃ
// 
//#define SDA_IN()  {GPIOA->MODER&=0X0FFFFFFF;GPIOB->CRH|=(u32)8<<28;}
//#define SDA_OUT() {GPIOB->CRH&=0X0FFFFFFF;GPIOB->CRH|=(u32)3<<28;}
// 
////IO¿Ú²Ù×÷º¯Êý     
//#define IIC_SCL    PBout(13) //SCL
//#define IIC_SDA    PBout(15) //Êä³öSDA     
//#define READ_SDA   PBin(15)  //ÊäÈëSDA 
#define BMP390_IIC2_READ_SDA HAL_GPIO_ReadPin(GPIOA, SDA_Pin)
#define BMP390_SDA_1 HAL_GPIO_WritePin(GPIOA, SDA_Pin, GPIO_PIN_SET)
#define BMP390_SCL_1    HAL_GPIO_WritePin(GPIOA, SCL_Pin, GPIO_PIN_SET)
 
#define BMP390_SDA_0 HAL_GPIO_WritePin(GPIOA, SDA_Pin, GPIO_PIN_RESET)
#define BMP390_SCL_0    HAL_GPIO_WritePin(GPIOA, SCL_Pin, GPIO_PIN_RESET)
 
 
//I2CËùÓвÙ×÷º¯Êý
void IIC_Init(void);                //³õʼ»¯I2CµÄIO¿Ú                 
void IIC_Start(void);                //·¢ËÍIIC¿ªÊ¼ÐźÅ
void IIC_Stop(void);                  //·¢ËÍIICÍ£Ö¹ÐźÅ
void IIC_Send_Byte(u8 txd);            //I2C·¢ËÍÒ»¸ö×Ö½Ú
u8 IIC_Read_Byte(unsigned char ack);//I2C¶Áȡһ¸ö×Ö½Ú
u8 IIC_Wait_Ack(void);                 //I2CµÈ´ýACKÐźÅ
void IIC_Ack(void);                    //I2C·¢ËÍACKÐźÅ
void IIC_NAck(void);                //I2C²»·¢ËÍACKÐźÅ
 
void IIC_Write_One_Byte(u8 daddr,u8 addr,u8 data);
u8 IIC_Read_One_Byte(u8 daddr,u8 addr);      
void  GetPressAndHeight();
#endif