@@ -63,13 +63,34 @@ bool Adafruit_NAU7802::begin(TwoWire *theWire) {
6363
6464 if (!reset ())
6565 return false ;
66+ if (!enable (true ))
67+ return false ;
6668 if (!setLDO (NAU7802_3V0))
6769 return false ;
6870 if (!setGain (NAU7802_GAIN_128))
6971 return false ;
7072 if (!setRate (NAU7802_RATE_10SPS))
7173 return false ;
72- if (!enable (true ))
74+
75+ // disable ADC chopper clock
76+ Adafruit_I2CRegister adc_reg = Adafruit_I2CRegister (i2c_dev, NAU7802_ADC);
77+ Adafruit_I2CRegisterBits chop =
78+ Adafruit_I2CRegisterBits (&adc_reg, 2 , 4 ); // # bits, bit_shift
79+ if (!chop.write (0x3 ))
80+ return false ;
81+
82+ // use low ESR caps
83+ Adafruit_I2CRegister pga_reg = Adafruit_I2CRegister (i2c_dev, NAU7802_PGA);
84+ Adafruit_I2CRegisterBits ldomode =
85+ Adafruit_I2CRegisterBits (&pga_reg, 1 , 6 ); // # bits, bit_shift
86+ if (!ldomode.write (0 ))
87+ return false ;
88+
89+ // PGA stabilizer cap on output
90+ Adafruit_I2CRegister pwr_reg = Adafruit_I2CRegister (i2c_dev, NAU7802_POWER);
91+ Adafruit_I2CRegisterBits capen =
92+ Adafruit_I2CRegisterBits (&pwr_reg, 1 , 7 ); // # bits, bit_shift
93+ if (!capen.write (1 ))
7394 return false ;
7495
7596 return true ;
@@ -286,3 +307,31 @@ NAU7802_SampleRate Adafruit_NAU7802::getRate(void) {
286307
287308 return (NAU7802_SampleRate)rate_select.read ();
288309}
310+
311+ /* *************************************************************************/
312+ /* !
313+ @brief Perform the internal calibration procedure
314+ @param mode The calibration mode to perform: NAU7802_CALMOD_INTERNAL,
315+ NAU7802_CALMOD_OFFSET or NAU7802_CALMOD_GAIN
316+ @returns True on calibrations success
317+ */
318+ /* *************************************************************************/
319+ bool Adafruit_NAU7802::calibrate (NAU7802_Calibration mode) {
320+ Adafruit_I2CRegister ctrl2_reg = Adafruit_I2CRegister (i2c_dev, NAU7802_CTRL2);
321+ Adafruit_I2CRegisterBits cal_start =
322+ Adafruit_I2CRegisterBits (&ctrl2_reg, 1 , 2 ); // # bits, bit_shift
323+ Adafruit_I2CRegisterBits cal_err =
324+ Adafruit_I2CRegisterBits (&ctrl2_reg, 1 , 3 ); // # bits, bit_shift
325+ Adafruit_I2CRegisterBits cal_mod =
326+ Adafruit_I2CRegisterBits (&ctrl2_reg, 2 , 0 ); // # bits, bit_shift
327+
328+ if (!cal_mod.write (mode))
329+ return false ;
330+ if (!cal_start.write (true ))
331+ return false ;
332+ while (!cal_start.read ()) {
333+ delay (10 );
334+ }
335+
336+ return !cal_err.read ();
337+ }
0 commit comments