光照模块 bh1750
需求 需要用 stm32 来驱动 bh1750 的光照模块 解决 使用硬件 I2C 来驱动,很简单 #include "i2c.h" #define BH1750_ADDRESS 0x23 //BH1750 #define BH1750_MODE_OTH 0x20 int32_t Bh1750GetValue() { uint8_t cmd[] = {BH1750_MODE_OTH}; uint8_t buf[2]; buf[0] = 0x00; HAL_I2C_Master_Transmit(&hi2c1, BH1750_ADDRESS << 1, cmd, 1, 1000); HAL_I2C_Master_Receive(&hi2c1, BH1750_ADDRESS << 1, buf, 2, 1000); int32_t value = (buf[0] << 8) | buf[1]; value = value/1.2; return value; } 参考 STM32应用开发——BH1750光照传感器详解 BH1750光强度传感器Stm32f103驱动(已测试ok) BH1750光照强度传感器 STM32外设系列—BH1750 STM32 读取 BH1750 光照强度数据打印到串口 STM32—DHT11温湿度传感器与BH1750FVI光照传感器(HAL库、含源码)