ad7746_read_capacitance.cpp 831 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <rtthread.h>
  2. #include <stdlib.h>
  3. #include <AD7746.h>
  4. #ifndef AD7746_I2C_NAME
  5. #define AD7746_I2C_NAME "i2c2"
  6. #endif
  7. static unsigned char c[2];
  8. static void ad7746_read_capacitance(int argc,char *argv[])
  9. {
  10. // Initialization
  11. AD7746 ad7746;
  12. ad7746.begin(AD7746_I2C_NAME);
  13. // Setup Cap
  14. c[0] = 0x81;
  15. ad7746.write(AD7746_REG_CAP_SETUP, c, 1);
  16. // Setup Excitation
  17. c[0] = 0x0B;
  18. ad7746.write(AD7746_REG_EXC_SETUP, c, 1);
  19. // Setup Sample
  20. c[0] = 0xA1;
  21. ad7746.write(AD7746_REG_CFG, c, 1);
  22. // Print Capacitance
  23. for(int i = 0; i< 5; i++)
  24. {
  25. rt_kprintf("\nCurrent Capacitance Percentage: %lu%\n", (ad7746.getCapData() - 8388608) * 100 / 8388608);
  26. rt_thread_mdelay(1000);
  27. }
  28. }
  29. MSH_CMD_EXPORT(ad7746_read_capacitance, ad7746 read capacitance example);