本帖最后由 jundao721 于 2017-4-5 18:11 编辑
BH1745NUC是一款16位数字颜色传感器,能够测量分析周围环境的RGB颜色能够自动调整显示屏画面和背光,该IC具有红外线过滤特性,据说在不同光照情况下,能够更准确地计算出照度和色温。被测试分别使用红色,绿色和蓝色的LED发光二极管做一下光照数据测试。 其光学灵敏度特性如图1所示: 该模块使用的IIC通讯,在这里使用STM32模拟IIC,设备初始化过程参考官方的Ardunio例程,重要程序如图2所示: - void BH1745_Init(void)
- {
- // u8 reg;
- // u8 buf[2];
- // u8 sensebit;
- wai = BH1745SingleRead(BH1745NUC_DEVICE_ADDRESS_39,BH1745NUC_SYSTEM_CONTROL);
- ID = BH1745SingleRead(BH1745NUC_DEVICE_ADDRESS_39,BH1745NUC_MANUFACTURER_ID);
- //step1
- BH1745Write(BH1745NUC_DEVICE_ADDRESS_39,0x61,0x03);
- BH1745Write(BH1745NUC_DEVICE_ADDRESS_39,BH1745NUC_MODE_CONTROL1,0x00);//12bit
-
- Delay_nnms(100);//(1);
- BH1745Write(BH1745NUC_DEVICE_ADDRESS_39,BH1745NUC_MODE_CONTROL2,0x92);
- Delay_nnms(100);
- BH1745Write(BH1745NUC_DEVICE_ADDRESS_39,BH1745NUC_MODE_CONTROL3,0x02);
- Delay_nnms(100);
- }
- void Get_RawVal(void)
- {
- //step4:
- RData = BH1745MulRead(BH1745NUC_DEVICE_ADDRESS_39,0x50);//red
- Delay_nnms(1000);
- GData = BH1745MulRead(BH1745NUC_DEVICE_ADDRESS_39,0x52);//green
- Delay_nnms(1000);
- BData = BH1745MulRead(BH1745NUC_DEVICE_ADDRESS_39,0x54);//blue
- Delay_nnms(1000);
- CData = BH1745MulRead(BH1745NUC_DEVICE_ADDRESS_39,0x56);//clear
- Delay_nnms(1000);
- }
复制代码Clearcolor网上说是透明色,我想可能是透明程度吧。正常光照下的采集值,不是很稳定,可能和光线变化有关系,如图3所示:
过两天连接到液晶屏再仔细研究研究。
|