12345678910111213141516171819202122232425262728 |
- #include "bexus_temperature_i2c.h"
- uint8_t i2c_temp[]={0x49,0x00,0x01};
- struct Dataset *data_i2c;
- uint8_t m_buff2[3];
- void Temperature_I2c_Init() {
- for(int i=0; i<sizeof(i2c_temp);i++)
- i2c_temp[i]=i2c_temp[i]<<1;
- }
- int Temperature_I2c_Read() {
- data_i2c = &Dataset_Master[buff_sensor_data_index];
-
- if(HAL_OK == HAL_I2C_Master_Transmit(&hi2c2,i2c_temp[0],&i2c_temp[1],1,10)) {
- HAL_I2C_Master_Receive(&hi2c2,i2c_temp[0],m_buff2,2,10);
- data_i2c->temperature_i2c_raw = m_buff2[0]<<8 | m_buff2[1];
- } else return HAL_ERROR;
-
- if(data_i2c->temperature_i2c_raw<32768){ //Temperaturberechnung
- data_i2c->temperature_i2c= data_i2c->temperature_i2c_raw*0.0078125;//wenn größer 0°C
- }else{
- data_i2c->temperature_i2c=(32768- data_i2c->temperature_i2c_raw)*0.0078125;
- }
- return HAL_OK;
- }
|