bexus_temperature_i2c.c 806 B

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