文章目录
##CubeMX IIC设置
HAL代码
void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 1;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = 0x44;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
}
ST HAL IIC库 底层设备通讯地址需要修改
这里原始只是将最后一位置0置1,修改如下
读取sht85温湿度数据
#define CRC_POLYNOMIAL 0x131 // P(x) = x^8 + x^5 + x^4 + 1 = 100110001
#define I2C_ADDR 0x44
/* USER CODE BEGIN PFP */
/* USER CODE END Includes */
static float CalcTemperature(uint16_t rawValue);
static float CalcHumidity(uint16_t rawValue);
void WriteCommand(etCommands command);
void SHT85_ReadSerialNumber1(uint32_t* serialNumber);
void SHT85_SingleMeasurment1(float* temperature, float* humidity,
etSingleMeasureModes measureMode,
uint8_t timeout);
uint8_t revbuff[10]={0,};
uint32_t serialNumber; // serial number
float temperature; // temperature
float humidity;
HAL_StatusTypeDef err0r;
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Priv