yincheng.zhong
2023-08-22 ce4dd5cba076e7ae21faffcc02ab0bf08d1b0949
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#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
 
/**\name Over sampling macros */
#define BMP3_NO_OVERSAMPLING                    UINT8_C(0x00)
#define BMP3_OVERSAMPLING_2X                    UINT8_C(0x01)
#define BMP3_OVERSAMPLING_4X                    UINT8_C(0x02)
#define BMP3_OVERSAMPLING_8X                    UINT8_C(0x03)
#define BMP3_OVERSAMPLING_16X                   UINT8_C(0x04)
#define BMP3_OVERSAMPLING_32X                   UINT8_C(0x05)
 
/**\name Filter setting macros */
#define BMP3_IIR_FILTER_DISABLE                 UINT8_C(0x00)
#define BMP3_IIR_FILTER_COEFF_1                 UINT8_C(0x01)
#define BMP3_IIR_FILTER_COEFF_3                 UINT8_C(0x02)
#define BMP3_IIR_FILTER_COEFF_7                 UINT8_C(0x03)
#define BMP3_IIR_FILTER_COEFF_15                UINT8_C(0x04)
#define BMP3_IIR_FILTER_COEFF_31                UINT8_C(0x05)
#define BMP3_IIR_FILTER_COEFF_63                UINT8_C(0x06)
#define BMP3_IIR_FILTER_COEFF_127               UINT8_C(0x07)
 
/**\name Odr setting macros */
#define BMP3_ODR_200_HZ                         UINT8_C(0x00)
#define BMP3_ODR_100_HZ                         UINT8_C(0x01)
#define BMP3_ODR_50_HZ                          UINT8_C(0x02)
#define BMP3_ODR_25_HZ                          UINT8_C(0x03)
#define BMP3_ODR_12_5_HZ                        UINT8_C(0x04)
#define BMP3_ODR_6_25_HZ                        UINT8_C(0x05)
#define BMP3_ODR_3_1_HZ                         UINT8_C(0x06)
#define BMP3_ODR_1_5_HZ                         UINT8_C(0x07)
#define BMP3_ODR_0_78_HZ                        UINT8_C(0x08)
#define BMP3_ODR_0_39_HZ                        UINT8_C(0x09)
#define BMP3_ODR_0_2_HZ                         UINT8_C(0x0A)
#define BMP3_ODR_0_1_HZ                         UINT8_C(0x0B)
#define BMP3_ODR_0_05_HZ                        UINT8_C(0x0C)
#define BMP3_ODR_0_02_HZ                        UINT8_C(0x0D)
#define BMP3_ODR_0_01_HZ                        UINT8_C(0x0E)
#define BMP3_ODR_0_006_HZ                       UINT8_C(0x0F)
#define BMP3_ODR_0_003_HZ                       UINT8_C(0x10)
#define BMP3_ODR_0_001_HZ                       UINT8_C(0x11)
 
 
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