#include "MSE5611.h" #define MSE5611_Slave 0xEC //#define MSE5611_Slave 0xEE #define MSE5611_Reset 0x1E #define Convert_D1_256 0x40 #define Convert_D1_512 0x42 #define Convert_D1_1024 0x44 #define Convert_D1_2048 0x46 #define Convert_D1_4096 0x48 #define Convert_D2_256 0x50 #define Convert_D2_512 0x52 #define Convert_D2_1024 0x54 #define Convert_D2_2048 0x56 #define Convert_D2_4096 0x58 #define ADC_Read 0x00 #define PROM_Read_0 0xA0 #define PROM_Read_1 0xA2 #define PROM_Read_2 0xA4 #define PROM_Read_3 0xA6 #define PROM_Read_4 0xA8 #define PROM_Read_5 0xAA #define PROM_Read_6 0xAC #define PROM_Read_7 0xAE #define Sea_Level_Pressure 101325.0 uint16_t Reserve = 0; uint16_t CFG[6] = {0}; uint16_t MSE5611_CRC = 0; uint32_t D[2] = {0}; int32_t Temp = 0; int32_t Press = 0; float Height = 0; int MSE5611_register_write_len(uint8_t addr,uint8_t register_address, uint8_t len,uint8_t *buf) { uint8_t w2_data[50],i; w2_data[0] = register_address; for(i=0;i>23); if(Temp < 2000) { T2 = ( dT*dT )>>31; OFF2 = 5 * (Temp - 2000) * (Temp - 2000) >> 1; SENS2 = 5 * (Temp - 2000) * (Temp - 2000) >> 2; } if(Temp < -1500) { OFF2 = OFF2 + 7 * (Temp + 1500) * (Temp + 1500); SENS2 = SENS2 + ( 11 * (Temp +1500) * (Temp +1500) >> 1 ); } OFF = (((int64_t)CFG[1]) << 16) + ((CFG[3] * dT) >> 7); SENS = (((int64_t)CFG[0]) << 15) + ((CFG[2] * dT) >> 8); OFF -= OFF2; Temp -= T2; SENS -= SENS2; Press = (((D[0] * SENS)>>21) - OFF)>>15; Height = 44330 * (1 - pow(Press/Sea_Level_Pressure ,1 / 5.225)); return Height; } void MSE5611_Config(void) { uint8_t i; uint8_t dd[2]; Reset_MSE5611(); MSE5611_register_read_len(MSE5611_Slave,PROM_Read_0,2,dd); Reserve = ((uint16_t)dd[0]<<8|dd[1]); printf("Reserve=%x\r\n",Reserve); for(i=0;i<6;i++){ MSE5611_register_read_len(MSE5611_Slave,PROM_Read_1+i*2,2,dd); CFG[i] = ((uint16_t)dd[0]<<8 | dd[1]); printf("CFG[%d]=%x\r\n",i,CFG[i]); } MSE5611_register_read_len(MSE5611_Slave,PROM_Read_7,2,dd); MSE5611_CRC = ((uint16_t)dd[0]<<8|dd[1]); printf("MSE5611_CRC=%x\r\n",MSE5611_CRC); }