Arduino Nano 读取ADS1100实例

利用Arduino Nano的wire库可以很方便对ADS1100进行设置和读取转换后的数据。

/*

*  Arduino reads ADS1100  I2C 16bit diff ADC

*/  



/* 

    SDA  ==>  analog 4  PC4

    SCL  ==>  analog 5  PC5



    set register:  STBY   0  0    SC    DR1  DR0 PGA1  PGA0

          default   1     0  0    0      1    1    0     0      0x8C

          i want    1     0  0    0      1    1    0     0

                    ign   0  0   con      8SPS      GAIN 1

    STBY, only for single mode to start conversion

    SC    1= single , 0=continuous 

    DR1:0    datarate 00 = 128sps, 12 bit      -2048 to  2047

                      01 =  32sps, 14          -8192 to  9191

                      10 =  16sps, 15         -16384 to 16383

                      11 =   8sps, 16         -32768 to 32767  

    PGA1:0  Gain      00 = *1, 01 = *2, 10 = *4, 11 = *8  

*/



#include <Wire.h>



//  AD0 1001 000 r/w      AD1 1001 001 r/w ; r=1. w=0     

#define AD0 B1001000         // ADS1100 地址0x48
#define options B10001100 // 0x8C-- 8SPS,16位精度,1倍放大 uint8_t reg = 0; int16_t result = 0; void setup() { Serial.begin(9600); Wire.begin(); Wire.beginTransmission(AD0); Wire.write(options); Wire.endTransmission(); } void loop() { Wire.beginTransmission(AD0); Wire.requestFrom(AD0, 3); // 返回 3个 bytes
      while(Wire.available()) {      

        result = Wire.read();     

        result = result << 8;

        result +=  Wire.read();

        reg = Wire.read();

        Serial.print(result, DEC); 

        Serial.println("\t");

        Serial.print((3300.00 * result)/ 0x7FFF, 2);//ADS1100接3.3V电源,如果接5V要将3300.00改为5000.00

        Serial.println(" mV");     

  }

  Wire.endTransmission();

  delay(100);

}

 

你可能感兴趣的:(arduino)