|
【背景】
因工作需要单片机测试Capella Micro公司的CM32181数字环境光线传感器, 一块小PCBA。
此芯片为3.3V供电和3.3V I2C总线,支持polling和interrupt双模式操作。
此芯片在Arduino圈较少见,调试OK后顺便整成了一个Arduino驱动库上传到github上
方便大家使用。很希望以后能有更多的人为Arduino兼容丰富芯片做努力!
【驱动库github地址】
https://github.com/ShineHua2017/CM32181_arduino
【芯片Data Sheet地址】
http://www.ibselectronics.com/ibsstore/datasheet/CM32181A3OP.pdf
【调试环境】
UNO x 1
5V-3.3V IO电平转换板(需要SCL,SDA两路) x 1
4.7K电阻(SCL,SDA上拉用) x 2
芯片传感器PCBA的FFC接口转排针小板 x 1
【示例代码】 - /* Arduino demo code for control Light Sensor chip -- CM32181
- * Setup chip on polling mode and read Lux value
- *
- * The circuit:
- * Ardunio CM32181
- * SDA <---> SDA
- * SCL <---> SCL
- *
- * library coding based on TWI library
- *
- * Written by Shine Hua
- * Email Address: [email protected] [email protected]
- *
- */
- #include <CM32181_arduino.h>
- //CM32181 ADDR pin pull high to select address 0x48
- //or low to select address 0x10
- CM32181 cm(0x10); //when ADDR pin connect GND
- void setup() {
-
- boolean error = false;
- uint16_t chip_id = 0;
- //uint16_t chip_status = 0;
-
- Serial.begin(9600);
-
- error = cm.init_chip();
- if(error == false){
- Serial.println("Not found chip device or init error!");
- while(true)
- {}
- }
-
- chip_id = cm.get_chip_ID();
- if(chip_id != 0x81){ //chip ID must be 0x81
- Serial.println("unknown chip!");
- while(true)
- {}
- }
-
- //chip_status = cm.get_chip_status();
- //error = cm.powerdown_chip();
- //error = cm.powerup_chip();
-
- }
- void loop() {
-
- uint16_t get_data = cm.read_sensor_raw(); //This is sensor raw data, not lux value. you need trans.
- String desc = "LUX raw data:";
- desc += get_data;
- Serial.println(desc);
- delay(5);
-
- }
复制代码
【细节部分】
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|