/* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm8l15x_i2c.h" #include "stm8l1526_eval.h" #include "stm8_eval_i2c_tsensor.h" /** * @addtogroup DEMO_Functions * @{ */ /* #define LM75_REG_TEMP 0xF6 // Temperature Register of LM75 // #define LM75_REG_CONF 0x01 // Configuration Register of LM75 / #define LM75_REG_THYS 0x02 // Temperature Register of LM75 // #define LM75_REG_TOS 0x03 /* Over-temp Shutdown threshold Register of LM75 // #define I2C_TIMEOUT (uint32_t)0x3FFFF /*!< I2C Time out // #define LM75_ADDR 0xEF /*!< LM75 address // #define LM75_I2C_SPEED 100000 /*!< I2C Speed // */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ volatile uint8_t a=1; uint16_t ACsix,ACfive,ACfour; //uint32_t Finalval; uint8_t i,f,d,z,lsb,msb,msb1,lsb1,MSB,LSB,msb2,lsb2,msb3,lsb3,LSBs,MSBs,ac1m,ac1l,ac2m,ac2l,ac3m,ac3l,ac4m,ac4l,b1m,b1l,mbm,mbl,dataid;//msb2,lsb2;//,LSBs,MSBs; int32_t X_1,X_2,Temperature,B_5,UT; int16_t MC,MD,MB,DataValue2,DataValue3,Btwo,Bone,ACone,ACtwo,ACthree,ACone2; //int8_t LSBs,MSBs,msb2,lsb2,msb3,lsb3; /* Private function prototypes -----------------------------------------------*/ //void PrintLogo(void); /* Private functions ---------------------------------------------------------*/ /* Public functions ----------------------------------------------------------*/ /** * @brief Main program. * @param None * @retval None */ void main(void) { // JOYState_TypeDef Key; //GPIO_Init(GPIOB,GPIO_Pin_1,GPIO_Mode_Out_PP_High_Fast); Init_Application(); LM75_DeInit(); LM75_Init(); /* while(1) { // GPIO_Pin_1=0; GPIO_ToggleBits(GPIOB,GPIO_Pin_1); WaitDelay(1); // GPIO_Pin_1=1; } */ while(1) { //if(a==1) // { // DataValue=LM75_ReadTemp(); /* LM75_WriteReg(BMP180_writReg,BMP180write); for(i=0;i<=5;i++) { for(z=0;z<=1000;z++); } */ //read check 0x55------------------------------------------------------------------------------------- dataid=LM75_ReadReg(ChipID55); //---------------------------------------------------------------------------------------------------- // read AC1 ac1m=LM75_ReadReg(BMP180_AC1_m); ac1l=LM75_ReadReg(BMP180_AC1_l); // ACone2 = (int16_t)((((int32_t)((int8_t)ac1m))<<8) | ac1l); // ACone2=(((int16_t)ac1m << 8) + ac1l); ACone=((uint16_t)ac1m<<8);//+lsb ACone|=ac1l; //------------------------------------------------------------------------------------- // read AC2 ac2m=LM75_ReadReg(BMP180_AC2_m); ac2l=LM75_ReadReg(BMP180_AC2_l); // ACone2 = (int16_t)((((int32_t)((int8_t)ac1m))<<8) | ac1l); // ACone2=(((int16_t)ac1m << 8) + ac1l); ACtwo=((uint16_t)ac2m<<8);//+lsb ACtwo|=ac2l; // read AC3 ac3m=LM75_ReadReg(BMP180_AC3_m); ac3l=LM75_ReadReg(BMP180_AC3_l); // ACone2 = (int16_t)((((int32_t)((int8_t)ac1m))<<8) | ac1l); // ACone2=(((int16_t)ac1m << 8) + ac1l); ACthree=((uint16_t)ac3m<<8);//+lsb ACthree|=ac3l; // read AC4 ac4m=LM75_ReadReg(BMP180_AC4_m); ac4l=LM75_ReadReg(BMP180_AC4_l); // ACone2 = (int16_t)((((int32_t)((int8_t)ac1m))<<8) | ac1l); // ACone2=(((int16_t)ac1m << 8) + ac1l); ACfour=((uint16_t)ac4m<<8);//+lsb ACfour|=ac4l; //------------------------------------------------------------------------------------- //READ for AC5------------------------------------------------------ msb=LM75_ReadReg(BMP180AC5m); lsb=LM75_ReadReg(BMP180AC5l); ACfive=((uint16_t)msb<<8);//+lsb ACfive|=lsb; // read for AC6------------------------------------------------- msb1=LM75_ReadReg(BMP180AC6m); lsb1=LM75_ReadReg(BMP180AC6l); ACsix=((uint16_t)msb1<<8);//+lsb ACsix|=lsb1; //---------------------------------------------------------------------------------------------------------------------------------- // read B1 b1m=LM75_ReadReg(BMP180B1m); b1l=LM75_ReadReg(BMP180B1l); Bone=((uint16_t)b1m<<8);//+lsb Bone|=b1l; // read B2 MSBs=LM75_ReadReg(BMP180B2m); LSBs=LM75_ReadReg(BMP180B2l); Btwo=((uint16_t)MSBs<<8);//+lsb Btwo|=LSBs; // Read for MB---------------------------------------------------- mbm=LM75_ReadReg(BMP180MBm); mbl=LM75_ReadReg(BMP180MBl); MB=((uint16_t)mbm<<8);//+lsb MB|=mbl; // Read for MC---------------------------------------------------- msb2=LM75_ReadReg(BMP180MCm); lsb2=LM75_ReadReg(BMP180MCl); MC=((uint16_t)msb2<<8);//+lsb MC|=lsb2; //READ For MD---------------------------------------------------- msb3=LM75_ReadReg(BMP180MDm); lsb3=LM75_ReadReg(BMP180MDl); MD=((uint16_t)msb3<<8);//+lsb MD|=lsb3; //*************************************************************************************************************************************** //write data in control register wait for 4.5ms then read data from 0xF6 and F7 LM75_WriteReg(BMP180_writReg,BMP180write); WaitDelay(1); //read data MSB = LM75_ReadReg(BMP180_MSB); LSB = LM75_ReadReg(BMP180_lsb); UT = (((uint16_t)MSB << 8)+LSB); // Calculation---- TEMPERATURE------- X_1 = (int32_t)(((int32_t)UT-ACsix)*(ACfive >> 15)); X_2 = (int32_t)((int32_t)MC << 11)/(X_1+MD); B_5 = (X_1 + X_2); Temperature = ((B_5+8) >> 4); // Calculation Pressure------------------------- //DataValue=(uint16_t)(z<<8); //i=LM75_ReadReg(BMP180_data2); // DataValue|=LM75_ReadReg(BMP180_data2); // } /* a=0; else if(a==0) {//WaitDelay(5); DataValue1=LM75_ReadTemp(); } */ } }